define(['ionic'], function () {
    var myApp = angular.module('myApp', ['ionic']);
    var issend = true;
    var isItemsend = true;
    var customerid = "";
    var customercode = "";
    var customername = "";
    var itemid = "";
    var itemcode = "";
    var itemname = "";

    myApp.run(function () {
        u9.hideLoading();
    });
    myApp.config(function ($stateProvider, $urlRouterProvider, $ionicConfigProvider) {

        $stateProvider
            .state('Home', {
                url: "/Home",
                templateUrl: 'Home.html'
            })
            .state('OrderList', {
                url: "/OrderList",
                templateUrl: 'OrderList.html'

            })
            .state('OrderHeadDetail', {
                url: "/OrderHeadDetail",
                templateUrl: 'OrderHeadDetail.html'

            })
            .state('OrderLineList', {
                url: "/OrderLineList",
                templateUrl: 'OrderLineList.html'

            })
            .state('SoLineDetail', {
                url: "/SoLineDetail",
                templateUrl: 'SoLineDetail.html'

            })
            .state('SoHead', {
                url: "/SoHead",
                templateUrl: 'SoHead.html'
            })

            .state('SoLine', {
                url: "/SoLine",
                templateUrl: 'SoLine.html'
            })
            .state('CreateOrderLineList', {
                url: "/CreateOrderLineList",
                templateUrl: 'CreateOrderLineList.html'
            })
            .state('Customer', {
                url: "/Customer",
                templateUrl: 'Customer.html'
            })
            .state('Item', {
                url: "/Item",
                templateUrl: 'Item.html'
            });

        $urlRouterProvider.otherwise("/Home");

        $ionicConfigProvider.platform.android.navBar.alignTitle('center');
        $ionicConfigProvider.platform.android.backButton.previousTitleText(false);
        $ionicConfigProvider.platform.android.navBar.transition('view');
        $ionicConfigProvider.platform.android.views.transition('ios');
        $ionicConfigProvider.platform.android.views.swipeBackEnabled(true);
        $ionicConfigProvider.platform.android.views.swipeBackHitWidth(45);
        $ionicConfigProvider.platform.android.tabs.style('standard');
        $ionicConfigProvider.platform.android.tabs.position('bottom');
        $ionicConfigProvider.platform.android.form.toggle('large');

        $ionicConfigProvider.platform.default.backButton.previousTitleText(false);
        $ionicConfigProvider.platform.default.backButton.text(false);
    });

    myApp.controller('myController', function ($scope, $state, $http, $ionicActionSheet, $ionicLoading, $ionicSlideBoxDelegate) {
        $scope.bind = function () {
            if ($scope.initSubline) {
                $ionicSlideBoxDelegate.slide($scope.SoLineDetailINDEX, 1);
                $scope.initSubline = false;
            }
        };
        $scope.linkToHome = function () {

            var rooturl = localStorage.getItem('rooturl');

            window.location.href = u9.linkToHome('', rooturl);

        };


        $scope.initdata = function () {
            var logindata = u9.getLoginData();
            var CurrentOrgCode = logindata.OrgCode;
            var UserCode = logindata.UserCode;
            var enterpriseid = logindata.EntCode;


            $scope.companylist = [];
            //所有组织
            if (issend == false) {
                u9.showLoading();

                // var baseUrl = 'http://20.1.38.136/mobile/login/';
                // var  ajaxurl = baseUrl + "/organizations?user_code=" + UserCode + "&enterprise_id=" + enterpriseid;
                // $scope.companylist=[];
                // $http.get(ajaxurl).success(function(data, status, headers, config) {
                //    $scope.companylist = data.organizations;
                // }).error(function(data, status, headers, config) {});
                // baseUrl = 'http://20.1.38.30/u9/api/v1/logininfo.aspx/';
                //baseUrl =window.localStorage.getItem('_portalUrl')+'/api/v1/logininfo.aspx/';
                //var ajaxurl = baseUrl + "/organizations?user_code=" + UserCode + "&enterprise_id=" + enterpriseid;
                var ajaxurl = 'http://' + u9.getConnectSetting().address + ':' + u9.getConnectSetting().port + '/u9_gateway/api/v1/logininfo.aspx/organizations?user_code=' + UserCode + '&enterprise_id=' + enterpriseid;
                $http.get(ajaxurl).success(function (data, status, headers, config) {

                    $scope.companylist = data.organizations;
                    //$scope.companylist.push(data.organizations);
                    $scope.test.code = customercode;
                    u9.hideLoading();
                }).error(function (data, status, headers, config) {
                    return u9.alert('error');
                    u9.hideLoading();
                });
                //alert($scope.companylist.code);
            } else {
                var data = {
                    code: customercode,
                    name: customername
                };
                $scope.companylist.push(data);
                $scope.$apply();
                $scope.test.code = customercode;
            }
            ;
        }


        $scope.inititemdata = function () {
            var logindata = u9.getLoginData();
            var CurrentOrgCode = logindata.OrgCode;
            var UserCode = logindata.UserCode;
            var enterpriseid = logindata.EntCode;

            $scope.itemcompanylist = [];
            //所有组织
            //var a='';
            if (isItemsend == false) {


                //baseUrl = 'http://20.1.38.30/u9/api/v1/logininfo.aspx/';
                //baseUrl =window.localStorage.getItem('_portalUrl')+'/api/v1/logininfo.aspx/';
                //var ajaxurl = baseUrl + "/organizations?user_code=" + UserCode + "&enterprise_id=" + enterpriseid;
                var ajaxurl = 'http://' + u9.getConnectSetting().address + ':' + u9.getConnectSetting().port + '/u9_gateway/api/v1/logininfo.aspx/organizations?user_code=' + UserCode + '&enterprise_id=' + enterpriseid;
                $http.get(ajaxurl).success(function (data, status, headers, config) {
                    $scope.itemcompanylist = data.organizations;
                    //$scope.itemcompanylist.push(data.organizations);
                    $scope.item.code = itemcode;
                }).error(function (data, status, headers, config) {
                });
            }
            //当前组织
            else {
                var data = {
                    code: itemcode,
                    name: itemname
                };
                $scope.itemcompanylist.push(data);
                $scope.$apply();
                $scope.item.code = itemcode;
            }
            ;
        }


        $scope.GoPage = function () {
            $state.go('Customer');
            var logindata = u9.getLoginData();
            var CurrentOrgCode = logindata.OrgCode;
            var searchCustomerCondition = {
                Code: "",
                OrgCode: CurrentOrgCode
            };
            var jsonData1 = {
                name: 'UFIDA.U9.ISV.MSV.IQueryCustomerService',
                params: [searchCustomerCondition],
                onSuccess: $scope.onCustomerSuccess,
                onFailure: $scope.onCustomerFailure
            };
            u9.callSV(jsonData1);
        }


        $scope.GoItemPage = function () {
            $state.go('Item');
            var logindata = u9.getLoginData();
            var CurrentOrgCode = logindata.OrgCode;
            var searchitemCondition1 = {
                Code: "",
                OrgCode: CurrentOrgCode
            };
            var jsonData1 = {
                name: 'UFIDA.U9.ISV.MSV.IQueryItemService',
                params: [searchitemCondition1],
                onSuccess: $scope.onItemSuccess,
                onFailure: $scope.onItemFailure
            };
            u9.callSV(jsonData1);
        }

        $scope.onSuccessGetMultiOrgRefLoadResultMDTOData1 = function (data) {
            issend = data.IsSend;
            customerid = data.DefaiutOrgInfo.ID;
            customercode = data.DefaiutOrgInfo.Code;
            customername = data.DefaiutOrgInfo.Name;
            return issend, customerid, customercode, customername;
        };


        $scope.onFailureGetMultiOrgRefLoadResultMDTOData1 = function (data) {
            u9.alert("Failure");
        }

        $scope.GetMultiOrgRefLoadResultMDTOData1 = function () {
            var logindata = u9.getLoginData();
            var CurrentOrgCode = logindata.OrgCode;
            var EntityFullName = "UFIDA.U9.CBO.SCM.Customer.Customer";

            var result = {
                name: 'UFIDA.U9.ISV.MDeptSV.IQueryDocSendService',
                params: [CurrentOrgCode, EntityFullName],
                onSuccess: $scope.onSuccessGetMultiOrgRefLoadResultMDTOData1,
                onFailure: $scope.onFailureGetMultiOrgRefLoadResultMDTOData1
            };
            u9.callSV(result);
        }

        $scope.GetMultiOrgRefLoadResultMDTOData1();


        $scope.onSuccessGetMultiOrgRefLoadResultMDTOData2 = function (data) {
            isItemsend = data.IsSend;
            itemid = data.DefaiutOrgInfo.ID;
            itemcode = data.DefaiutOrgInfo.Code;
            itemname = data.DefaiutOrgInfo.Name;
            return isItemsend, itemid, itemcode, itemname;
        };


        $scope.onFailureGetMultiOrgRefLoadResultMDTOData2 = function (data) {
            u9.alert("Failure");
        }

        $scope.GetMultiOrgRefLoadResultMDTOData2 = function () {
            var logindata = u9.getLoginData();
            var CurrentOrgCode = logindata.OrgCode;
            var EntityFullName = "UFIDA.U9.CBO.SCM.Item.ItemMaster";

            var result = {
                name: 'UFIDA.U9.ISV.MDeptSV.IQueryDocSendService',
                params: [CurrentOrgCode, EntityFullName],
                onSuccess: $scope.onSuccessGetMultiOrgRefLoadResultMDTOData2,
                onFailure: $scope.onFailureGetMultiOrgRefLoadResultMDTOData2
            };
            u9.callSV(result);
        }

        $scope.GetMultiOrgRefLoadResultMDTOData2();

        $scope.mytemp = {
            myordercount: 0,
            UnSubmitCount: 0,
            UnApproveCount: 0,
            UnThingCount: 0,
            LizhangCount: 0,
            OrgName: "",
            UserName: ""
        }
        //home页查询订单数--开始
        $scope.onQueryCountSuccess = function (data) {
            u9.hideLoading();
            $scope.mytemp = {
                myordercount: data.TotalCount,
                UnSubmitCount: data.SubmitCount,
                UnApproveCount: data.AuditCount,
                UnThingCount: data.DeliveryCount,
                LizhangCount: data.LizhangCount,
                OrgName: data.OrgName,
                UserName: data.UserName
            }
            $scope.$apply();
        }

        var onQueryCountError = function (data) {
            u9.hideLoading();
            u9.alert("error");
            $scope.bb = "aa";
        }


        $scope.myFunc = function () {
            var logindata = u9.getLoginData();

            //var logindata=JSON.parse(logindata);
            //logindata.UserCode
            var userinfo = {
                CreateBy: logindata.UserCode,
                OrgId: logindata.OrgCode
            };

            var jsonData = {
                name: 'UFIDA.U9.ISV.SM.SOShipAppSV.IGetSOQty',
                params: [logindata.UserCode, logindata.OrgCode],
                onSuccess: $scope.onQueryCountSuccess,
                onFailure: onQueryCountError
            };
            u9.showLoading();
            u9.callSV(jsonData);
        }

        $scope.myFunc();

        //home页查询订单数--开始


        //orderlist页---开始

        //初始化选中日期为：本月
        $scope.temptest = {
            filtervalue: '',
            filterstate: 3
        };

        //查询界面数据源的条件，必用项
        $scope.date1 = "";
        $scope.date2 = "";

        //选择日期方法
        $scope.mySelectFunction = function () {
            var todaydate = new Date();
            //0:全部 1：今天 2:本周 3:本月 4：本季 5：本年 6：昨天 7：上周 8：上月 9：上季 10：去年
            if ($scope.temptest.filterstate == 0) {
                //为空弹出aaa
                $scope.date1 = "";
                $scope.date2 = "";
            } else if ($scope.temptest.filterstate == 1) {
                var dd = new Date();
                var monthtemp = '';
                if (parseInt(dd.getMonth()) + 1 > 9) {
                    monthtemp = (parseInt(dd.getMonth()) + 1).toString();
                } else {

                    monthtemp = "0" + (parseInt(dd.getMonth()) + 1).toString();
                }


                $scope.date1 = dd.getFullYear() + '-' + monthtemp + '-' + dd.getDate();
                $scope.date2 = "";


            } else if ($scope.temptest.filterstate == 2) {
                var now = new Date();
                var start = new Date();
                var end = new Date();
                var n = now.getDay();
                start.setDate(now.getDate() - n + 1);
                end.setDate(now.getDate() - n + 7);
                $scope.date1 = start.getFullYear() + "-" + (start.getMonth() + 1) + "-" + start.getDate();
                $scope.date2 = end.getFullYear() + "-" + (end.getMonth() + 1) + "-" + end.getDate();
            } else if ($scope.temptest.filterstate == 3) {
                var start = new Date();
                start.setDate(1); //第一天
                var end = new Date(start);
                end.setMonth(start.getMonth() + 1);
                end.setDate(0);
                $scope.date1 = start.getFullYear() + "-" + (start.getMonth() + 1) + "-" + start.getDate();
                $scope.date2 = end.getFullYear() + "-" + (end.getMonth() + 1) + "-" + end.getDate();
            } else if ($scope.temptest.filterstate == 4) {
                //本季度
                var now = new Date(); //当前日期
                var nowDayOfWeek = now.getDay(); //今天本周的第几天
                var nowDay = now.getDate(); //当前日
                var nowMonth = now.getMonth(); //当前月
                var nowYear = now.getYear(); //当前年
                nowYear += (nowYear < 2000) ? 1900 : 0; //
                var quarterStartDate = new Date(nowYear, dd(nowMonth), 1);
                var cc = tt(quarterStartDate);

                var quarterEndMonth = dd() + 2;
                var quarterStartDate = new Date(nowYear, quarterEndMonth, cc(quarterEndMonth));
                var dd = tt(quarterStartDate);
            } else if ($scope.temptest.filterstate == 5) {
                var d = new Date(); //当前日期
                $scope.date1 = d.getFullYear() + "-1-1";
                $scope.date2 = d.getFullYear() + "-12-31";
            }
            ;
        }

        $scope.SOLineDetailItemArrowFlag = true;
        $scope.sendpagename = function (titlename) {
            var pagename = titlename;
            $state.go('OrderList');
            var status = 0;
            var filterstr = "";
            switch (titlename) {
                case "全部订单":
                    filterstr = "";
                    status = 0;
                    $scope.SOLineDetailItemArrowFlag = false;
                    break;
                case "待提交订单":
                    filterstr = " and  Status=1 and IsHolded=0 and Cancel.Canceled =0";
                    status = 1;
                    $scope.SOLineDetailItemArrowFlag = false;
                    break;
                case "待审核订单":
                    filterstr = " and  Status=2 and IsHolded=0 and Cancel.Canceled =0";
                    status = 2;
                    $scope.SOLineDetailItemArrowFlag = false;
                    break;
                case "待发货订单":
                    filterstr = " and  Status=3 and IsHolded=0 and Cancel.Canceled =0";
                    status = 3;
                    $scope.SOLineDetailItemArrowFlag = false;
                    break;
                case "待立账订单":
                    filterstr = " and  Status=3 and IsHolded=0  and Cancel.Canceled =0 ";
                    status = 4;
                    $scope.SOLineDetailItemArrowFlag = false;
                    break;
            }
            $scope.pagename = pagename;
            $scope.filterstr = filterstr;
            $scope.typeflag = status;

            //增加第一次加载标志
            $scope.FirstInitOrderlist = true;
            //原来的方法，不要了 $scope.InitToolBtnVisible();
            $scope.InitOrderlist();
            if ($scope.pagename !== "待发货订单" && $scope.pagename !== "待立账订单") {
                $scope.orderlistcanceloption(); //订单列表编辑按钮显示
            } else {
                $scope.orderlistToolbtnflag = false;
                $scope.orderlistcancelbtnflag = false;
                $scope.orderlistsubmitbtnflag = false;
                $scope.Orderlistdeletebtnflag = false;
            }

        }

        $scope.data = {
            search_date: "",
            search_orderno: ""
        };

        $scope.filterstr = "";
        $scope.pagename = "";
        $scope.typeflag = 0;

        //清空输入框
        $scope.clearInput = function () {
            $scope.data.search_date = "";
            $scope.data.search_orderno = "";
        };

        var logindata = u9.getLoginData();


        //初始化界面时订单数据--开始
        $scope.SOHeadArr = []; //界面绑定数据源
        $scope.InitOrderList = [];
        var onInitOrderlistSuccess = function (data) {
            u9.hideLoading();

            //遍历订单列表 data
            for (var i = 0; i < data.length; i++) {
                $scope.isUnShiped = true;
                $scope.isUnAccount = true;
                //一条订单即单头 head
                var mID = data[i].ID;
                var mStatus = data[i].Status;
                var mdocno = data[i].DocNo;
                var Sysversion = data[i].Sysversion;
                //交易总金额
                //  var mtotalmoney = data[i].m_totalMoney;
                //客户
                var mcustomer = {
                    ID: data[i].Customer.ID,
                    Code: data[i].Customer.Code,
                    Name: data[i].Customer.Name
                };
                //币种
                var mCurrency = {
                    ID: data[i].Currency.ID,
                    Code: data[i].Currency.Code,
                    Name: data[i].Currency.Name,
                    ShortName: data[i].Currency.Shortname,
                    Symbol: data[i].Currency.Symbol
                };


                //生成订单日期
                var mbusinesDate = ""; //data[i].m_businessDate;

                //增加行数组 tmpsolines 即多行数据
                var tmpsolines = [];

                //价税合计总值
                var tmpTotalMoney = 0;

                //单行--开始
                for (var j = 0; j < data[i].SOLine.length; j++) {
                    var id = data[i].SOLine[j].ID;
                    //var mSoline={LineNum:}; 行号
                    var linenum = data[i].SOLine[j].LineNum;
                    //fangxia_20140902
                    //是否删除标志
                    var DeleteFlag = data[i].SOLine[j].DeleteFlag
                    //生成料品（Code Name）
                    var iteminfo = {
                        ID: data[i].SOLine[j].Item.ID,
                        Code: data[i].SOLine[j].Item.Code,
                        Name: data[i].SOLine[j].Item.Name
                    };
                    //计价单位
                    var mun = {
                        ID: data[i].SOLine[j].Unit.ID,
                        Code: data[i].SOLine[j].Unit.Code,
                        Name: data[i].SOLine[j].Unit.Name
                    };

                    //数量
                    var mOrderByQtyPU = data[i].SOLine[j].Amount;

                    //定价
                    var mOrderPriceTC = data[i].SOLine[j].Price;

                    //价税合计
                    var mTotalMoney = data[i].SOLine[j].TotalMoney;

                    tmpTotalMoney = tmpTotalMoney + parseFloat(mTotalMoney);
                    //单行中 销售订单行累计信息SOLineSumInfo的“累计出货量”
                    var m_sumShipAmount = data[i].SOLine[j].SumShipAmount;

                    //单行中 销售订单行累计信息SOLineSumInfo的 已立账数量1  “累计立账数量”(销售单位)
                    var m_sumAccureAmount = data[i].SOLine[j].SumAccureAmount;

                    //单行中 销售订单行累计信息SOLineSumInfo的累“计立账金额”(交易币种)
                    var m_sumAccureMoney = data[i].SOLine[j].SumAccureMoney;

                    //单行中 销售订单行累计信息SOLineSumInfo的累计退货扣款金额(交易币种)
                    var m_sumPayMoney = data[i].SOLine[j].SumPayMoney;

                    //如果行有订单子航 ShipPlanQtyPU
                    var mShipline = [];
                    if (data[i].SOLine[j].SOShipLineDTO.length > 0) {
                        for (var k = 0; k < data[i].SOLine[j].SOShipLineDTO.length; k++) {
                            var tempshipline = {
                                ID: data[i].SOLine[j].SOShipLineDTO[k].ID,
                                SublineNo: data[i].SOLine[j].SOShipLineDTO[k].DocSubLineNo,
                                RequiredDate: data[i].SOLine[j].SOShipLineDTO[k].RequiredDate,
                                ShipPlanQtyPU: data[i].SOLine[j].SOShipLineDTO[k].ShipPlanQtyPU,
                                ShipPlanQtyTU: data[i].SOLine[j].SOShipLineDTO[k].ShipPlanQtyTU,
                                TUToTBURate: data[i].SOLine[j].SOShipLineDTO[k].TUToTBURate,
                                ShipPlanQtyTBU: data[i].SOLine[j].SOShipLineDTO[k].ShipPlanQtyTBU,
                                SOShipLineSumInfo_SumReturnReShipQtyTU: data[i].SOLine[j].SOShipLineDTO[k].SOShipLineSumInfo_SumReturnReShipQtyTU,
                                SOShipLineSumInfo_ShipTakeQtyTBU: data[i].SOLine[j].SOShipLineDTO[k].SOShipLineSumInfo_ShipTakeQtyTBU,
                                SOShipLineSumInfo_ShipTakeQtyTU: data[i].SOLine[j].SOShipLineDTO[k].SOShipLineSumInfo_ShipTakeQtyTU,
                                SOShipLineSumInfo_SumConfirmQtyPU: data[i].SOLine[j].SOShipLineDTO[k].SOShipLineSumInfo_SumConfirmQtyPU,
                                SOShipLineSumInfo_SumReturnReShipQtyTBU: data[i].SOLine[j].SOShipLineDTO[k].SOShipLineSumInfo_SumReturnReShipQtyTBU
                            }

                            //待发货
                            if ($scope.typeflag == 3) {
                                var bb = tempshipline.ShipPlanQtyTU * tempshipline.TUToTBURate;
                                var cc = tempshipline.ShipPlanQtyTBU;
                                var dd = tempshipline.SOShipLineSumInfo_SumReturnReShipQtyTU * tempshipline.TUToTBURate + tempshipline.SOShipLineSumInfo_SumReturnReShipQtyTBU;
                                var ee = tempshipline.SOShipLineSumInfo_ShipTakeQtyTU * tempshipline.TUToTBURate + tempshipline.SOShipLineSumInfo_ShipTakeQtyTBU;
                                var aa = bb + cc + dd - ee;
                                //只要有一行没发货就是待发货
                                if ((bb + cc + dd - ee) > 0) {
                                    //是要发货的子行，继续查找
                                    //continue;
                                } else {
                                    //不是发货字行
                                    //$scope.isUnShiped=false;
                                    //应该跳到下一条订单头开始处
                                    continue;
                                }
                                ;
                            }
                            ;
                            //待立账
                            if ($scope.typeflag == 4) {
                                var ff = tempshipline.ShipPlanQtyPU - tempshipline.SOShipLineSumInfo_SumConfirmQtyPU;
                                if ((tempshipline.ShipPlanQtyPU - tempshipline.SOShipLineSumInfo_SumConfirmQtyPU) > 0) {

                                } else {
                                    continue;
                                }
                            }
                            ;
                            var mRequireDate = new Date(data[i].SOLine[j].SOShipLineDTO[k].RequiredDate);
                            if (k == 0) {
                                var monthtemp = '';
                                var today = '';
                                if (parseInt(mRequireDate.getMonth()) + 1 > 9) {
                                    monthtemp = (parseInt(mRequireDate.getMonth()) + 1).toString();
                                } else {

                                    monthtemp = "0" + (parseInt(mRequireDate.getMonth()) + 1).toString();
                                }

                                if (parseInt(mRequireDate.getDate()) > 9) {
                                    today = (parseInt(mRequireDate.getDate())).toString();
                                } else {
                                    today = "0" + (parseInt(mRequireDate.getDate())).toString();
                                }

                                mbusinesDate = mRequireDate.getFullYear() + '-' + monthtemp + '-' + today;

                            }
                            ;

                            mShipline.push(tempshipline);
                        }
                        ;
                    }
                    ;
                    //如果是待发货--行
                    if ($scope.typeflag == 3) {
                        if (mShipline.length == 0) {
                            continue;
                        }
                        ;
                    }
                    ;

                    if ($scope.typeflag == 4) {
                        if (mShipline.length == 0) {
                            continue;
                        }
                        ;
                    }
                    ;

                    //订单行
                    var tmpsoline = {
                        ID: id,
                        Linenum: linenum,
                        //20140902
                        DeleteFlag: DeleteFlag,
                        ItemInfo: iteminfo,
                        UN: mun,
                        OrderByQtyPU: mOrderByQtyPU,
                        OrderPriceTC: mOrderPriceTC,
                        TotalMoney: mTotalMoney,
                        SumShipAmount: m_sumShipAmount,
                        SumAccureAmount: m_sumAccureAmount,
                        SumAccureMoney: m_sumAccureMoney,
                        SumPayMoney: m_sumPayMoney,
                        RequireDate: mbusinesDate,
                        ShipLine: mShipline
                    };

                    tmpsolines.push(tmpsoline);

                }
                ;
                //单行--结束
                //订单头
                if ($scope.typeflag == 3) {
                    if (tmpsolines.length == 0) {
                        continue;
                    }
                    ;
                }
                ;
                if ($scope.typeflag == 4) {
                    if (tmpsolines.length == 0) {
                        continue;
                    }
                    ;
                }
                ;

                var so = {
                    ID: mID,
                    Status: mStatus,
                    DocNo: mdocno,
                    TotalMoney: tmpTotalMoney.toFixed(2),
                    Customer: mcustomer,
                    Currency: mCurrency,
                    BusinesDate: mbusinesDate,
                    SoLines: tmpsolines,
                    Sysversion: Sysversion
                };
                tmpTotalMoney = 0;
                $scope.InitOrderList.push(so);
                //$scope.apply();
            }
            ;
            $scope.searchOrdera($scope.date1, $scope.date2, $scope.temptest.filtervalue);

        }

        var onInitOrderlistError = function (data) {
            u9.hideLoading();
        }

        $scope.InitOrderlist = function () {
            $scope.InitOrderList.length = 0;
            //第一次加载全部数据
            if ($scope.FirstInitOrderlist) {
                var start = new Date();
                start.setDate(1); //第一天
                var end = new Date(start);
                end.setMonth(start.getMonth() + 1);
                end.setDate(0);
                //alert("第一天：" + new XDate(firstDate).toString('yyyy-MM-dd') + " 最后一天：" + new XDate(endDate).toString('yyyy-MM-dd'));
                $scope.date1 = start.getFullYear() + "-" + (start.getMonth() + 1) + "-" + start.getDate();
                $scope.date2 = end.getFullYear() + "-" + (end.getMonth() + 1) + "-" + end.getDate();
                $scope.FirstInitOrderlist = false;
            } else {
                //

            }


            var queryData = {
                CreatedBy: logindata.UserCode,
                Org: logindata.OrgCode,
                Filter: $scope.filterstr
            }

            var jsonData = {
                name: 'UFIDA.U9.ISV.SM.IQuerySODetailSevice',
                params: [logindata.UserCode, logindata.OrgCode, $scope.filterstr],
                onSuccess: onInitOrderlistSuccess,
                onFailure: onInitOrderlistError
            };
            u9.showLoading();
            u9.callSV(jsonData);
            // console.log($scope.filterstr);
            //u9.showLoading();

        }
        //订单列表数据加载--结束

        //初始化界面时订单数据--结束


        //“查询”订单详情列表--开始

        $scope.searchOrderaClick = function () {
            u9.showLoading();
            $scope.searchOrdera($scope.date1, $scope.date2, $scope.temptest.filtervalue);
        }

        $scope.searchOrdera = function (date1, date2, inputtext) {

            if (!$scope.InitOrderList) {
                u9.hideLoading();
                return;
            }
            ;
            //三个条件为空
            if (!date1 && !date2 && !inputtext) {
                $scope.selectordersbynull();
            } else if (!date1 && !date2 && inputtext) {
                //只输入订单号 客户名
                $scope.selectordersbyinput(inputtext);
            } else if (!date2 && !inputtext) {
                $scope.selectordersbydate1(date1);
            } else if (date2 && !inputtext) {
                $scope.selectordersbydate1date2(date1, date2);
            } else if (!date2 && inputtext) {
                $scope.selectordersbydate1input(date1, inputtext);
            } else if (date2 && inputtext) {
                $scope.selectordersbydate1date2input(date1, date2, inputtext);
            } else {
                $scope.selectordersbynull();
            }
        };

        //根据条件过滤数据  date1,date2,inputtext

        $scope.selectordersbynull = function () {
            $scope.SOHeadArr.length = 0;

            for (var i = 0; i < $scope.InitOrderList.length; i++) {
                $scope.SOHeadArr.push($scope.InitOrderList[i]);
            }
            u9.hideLoading();

        }

        $scope.selectordersbydate1 = function (date1) {
            //数组清空
            $scope.SOHeadArr.length = 0;
            var d1 = (new Date(date1.replace(/-/g, "/"))).getTime();
            for (var i = 0; i < $scope.InitOrderList.length; i++) {
                var d2 = (new Date($scope.InitOrderList[i].BusinesDate.replace(/-/g, "/"))).getTime();
                if (d1 == d2) {
                    $scope.SOHeadArr.push($scope.InitOrderList[i]);
                }
            }
            u9.hideLoading();
        }

        $scope.selectordersbydate1date2 = function (date1, date2) {
            $scope.SOHeadArr.length = 0;
            var begin = (new Date(date1.replace(/-/g, "/"))).getTime();
            var end = (new Date(date2.replace(/-/g, "/"))).getTime();
            for (var i = 0; i < $scope.InitOrderList.length; i++) {
                var tmptime = (new Date($scope.InitOrderList[i].BusinesDate.replace(/-/g, "/"))).getTime();
                if (tmptime >= begin && tmptime <= end) {
                    $scope.SOHeadArr.push($scope.InitOrderList[i]);
                }
            }
            u9.hideLoading();
            // console.log($scope.SOHeadArr);
            $scope.$apply();
        }

        $scope.selectordersbyinput = function (input) {
            $scope.SOHeadArr.length = 0;
            for (var i = 0; i < $scope.InitOrderList.length; i++) {
                if ($scope.InitOrderList[i].DocNo.toLowerCase().indexOf(input.toLowerCase()) >= 0 || $scope.InitOrderList[i].Customer.Name.toLowerCase().indexOf(input.toLowerCase()) >= 0) {
                    $scope.SOHeadArr.push($scope.InitOrderList[i]);
                }
            }
            u9.hideLoading();
        }

        $scope.selectordersbydate1input = function (date1, input) {
            $scope.SOHeadArr.length = 0;
            var d1 = (new Date(date1.replace(/-/g, "/"))).getTime();
            for (var i = 0; i < $scope.InitOrderList.length; i++) {
                var d2 = (new Date($scope.InitOrderList[i].BusinesDate.replace(/-/g, "/"))).getTime();
                if (d2 == d1 && ($scope.InitOrderList[i].DocNo.toLowerCase().indexOf(input.toLowerCase()) >= 0 || $scope.InitOrderList[i].Customer.Name.toLowerCase().indexOf(input.toLowerCase()) >= 0)) {
                    $scope.SOHeadArr.push($scope.InitOrderList[i]);
                }
            }
            u9.hideLoading();
        }


        $scope.selectordersbydate1date2input = function (date1, date2, input) {
            $scope.SOHeadArr.length = 0;
            var begin = (new Date(date1.replace(/-/g, "/"))).getTime();
            var end = (new Date(date2.replace(/-/g, "/"))).getTime();
            for (var i = 0; i < $scope.InitOrderList.length; i++) {
                var tmptime = (new Date($scope.InitOrderList[i].BusinesDate.replace(/-/g, "/"))).getTime();

                if (tmptime >= begin && tmptime <= end && ($scope.InitOrderList[i].DocNo.toLowerCase().indexOf(input.toLowerCase()) >= 0 || $scope.InitOrderList[i].Customer.Name.toLowerCase().indexOf(input.toLowerCase()) >= 0)) {
                    $scope.SOHeadArr.push($scope.InitOrderList[i]);
                }

            }
            u9.hideLoading();
            //$scope.$apply();
        }


        //查询订单详情结束---结束

        //点击客户 日期排序按钮
        <!--控制日期按钮显示-->
        $scope.dateFlag = 'BusinesDate';
        //$scope.cusFlag = 'Customer.Name';
        $scope.tempFlag1 = "button-positive";
        $scope.tempFlag2 = "button-light";
        $scope.showDateDiv = function () {
            $scope.dateFlag = 'BusinesDate';
            //$scope.cusFlag = 'Customer.Name';
            $scope.tempFlag1 = "button-positive";
            $scope.tempFlag2 = "button-light";
        };

        <!--控制客户按钮显示-->
        $scope.showCusDiv = function () {
            $scope.dateFlag = 'Customer.Name';
            //$scope.cusFlag = true;
            $scope.tempFlag2 = "button-positive";
            $scope.tempFlag1 = "button-light";
        };

        //页面传值到headdetail
        $scope.tempIndex = 0;
        $scope.selectdate = "";
        $scope.sendId = function (soid) {
            $scope.orderlistcanceloption(); //按钮回复初始化
            if ($scope.pagename !== "待发货订单" && $scope.pagename !== "待立账订单") {
                $scope.orderheaddetaileditflag = true; //订单头明细画面编辑按钮显示
                $scope.orderheaddetailcancelflag = false;
                $scope.orderheaddetailaddlineflag = false;
                //fangxia3.24
                $scope.OrderLineListcancelclick(); //订单列表画面编辑按钮显示
                $scope.OrderLineListaddlineflag = true;

            } else {
                $scope.orderheaddetaileditflag = false;
                $scope.orderheaddetailcancelflag = false;
                $scope.orderheaddetailaddlineflag = false;
                //fangxia3.24
                $scope.OrderLineListeditflag = false;
                $scope.OrderLineListcancelflag = false;
                $scope.OrderLineListaddlineflag = false;
                $scope.OrderLineListdeletelineflag = false;
            }
            for (var i = 0; i < $scope.SOHeadArr.length; i++) {
                if ($scope.SOHeadArr[i].ID == soid) {
                    $scope.tempIndex = i;
                    break;
                }
                ;
            }
            ;
            //$scope.tempIndex = index;
            //生成订单头详情
            //alert("我是orderlist");
            $scope.$emit('CtrlFromOrderlist', $scope.SOHeadArr[$scope.tempIndex]);
            if ($scope.SOHeadArr[$scope.tempIndex].Status == 0) {
                $scope.Status = "草稿";
            }
            if ($scope.SOHeadArr[$scope.tempIndex].Status == 1) {
                $scope.Status = "开立";
            }
            if ($scope.SOHeadArr[$scope.tempIndex].Status == 2) {
                $scope.Status = "审核中";
            }
            if ($scope.SOHeadArr[$scope.tempIndex].Status == 3) {
                $scope.Status = "审核";
            }
            if ($scope.SOHeadArr[$scope.tempIndex].Status == 4) {
                $scope.Status = "自然关闭";
            }
            if ($scope.SOHeadArr[$scope.tempIndex].Status == 5) {
                $scope.Status = "短缺关闭";
            }
            if ($scope.SOHeadArr[$scope.tempIndex].Status == 6) {
                $scope.Status = "超额关闭";
            }
            $scope.INDEX = $scope.tempIndex;
            $scope.selectdate = $scope.SOHeadArr[$scope.tempIndex].BusinesDate;
            // $state.go('OrderHeadDetail');
            $state.go('OrderLineList');
        }
        //张晓东-控制批量修改功能-开始
        //初始化按钮非选中态
        $scope.checkedFlag = false;

        $scope.myList = [];

        $scope.CreateSolinesDataSource = function () {
            $scope.myList = $scope.SOHeadArr[tempIndex].SoLines;
        }


        $scope.slideIndex = 0;
        $scope.slideChanged = function (index) {
            $scope.slideIndex = index;
            //$scope.SoLineDetailINDEX=index+1;
        };
        //$scope.tempmonth=$scope.myList[0].month;

        $scope.nextSlide = function () {
            $ionicSlideBoxDelegate.next();
            //$scope.linelistindex=index+1;
        };

        $scope.previous = function () {
            $ionicSlideBoxDelegate.previous();
            //$scope.linelistindex=index-1;
        };
        //计算选中对象个数
        $scope.myCount = function () {
            var temp = 0;
            angular.forEach($scope.SOHeadArr, function (a) {
                temp += a.checked ? 1 : 0;
            });
            return temp;
        }

        //存储要删除对象
        $scope.useIdArr = [];
        $scope.pushId = function (name) {
            $scope.useIdArr.length = 0;
            var ids = document.getElementsByName(name);
            for (var i = 0; i < ids.length; i++) {
                if (ids[i].checked == true) {
                    var temp = ids[i].getAttribute('value');
                    $scope.useIdArr.push(temp);
                }
            }
        }


        //提交按钮
        $scope.onSubmitSuccess = function (data) {
            u9.hideLoading();
            //$scope.useIdArr = [];
            var aa = $scope.useIdArr.length;
            var bb = 0;
            for (var i = 0; i < data.length; i++) {
                if (data[i].IsSucceed) {
                    bb += 1;
                }
                ;
            }
            ;
            var cc = aa - bb;
            u9.alert("共提交" + aa + "条，成功" + bb + "条,失败" + cc + "条");
            $scope.useIdArr = [];
            $scope.InitOrderlist();
        };

        $scope.onSubmitFailure = function (data) {
            u9.hideLoading();
            $scope.useIdArr = [];
            u9.alert("提交失败");
            $scope.InitOrderlist();
        };

        $scope.OrderlistsubmitChecked = function () {
            $scope.pushId('userchecked');
            if ($scope.myCount() <= 0) {
                u9.alert('请选中要提交的记录');
                return;
            }
            ;

            u9.confirm('确定要提交吗？').then(function (result) {
                if (result) {
                    u9.showLoading();
                    $scope.orderlistcanceloption(); //按钮回复初始化
                    var SODTO = [];
                    //组合数据参数
                    for (var i = 0; i < $scope.useIdArr.length; i++) {
                        var soid = $scope.useIdArr[i];
                        for (k = 0; k < $scope.SOHeadArr.length; k++) {

                            if ($scope.SOHeadArr[k].ID == soid) {
                                var sysversion = $scope.SOHeadArr[k].Sysversion;
                                var status = $scope.SOHeadArr[k].Status;
                                if (status != 1) {
                                    continue;
                                }
                                ;
                                var item = {
                                    SOkey: soid,
                                    SOSysVersion: sysversion,
                                    ErrorMessage: '',
                                    IsSucceed: true
                                };
                                SODTO.push(item);
                            }
                        }
                    }
                    if (SODTO.length <= 0) {
                        u9.alert("您所选订单是非开立状态订单，请重新选择！");
                        u9.hideLoading();
                        return;
                    }
                    ;
                    var FieldNameValues = [{
                        FieldName: 'Status',
                        FieldValue: '2'
                    }];
                    var isSRVUpd = true;
                    var result = {
                        name: 'UFIDA.U9.ISV.SM.SOShipAppSV.ISubmitSOSV',
                        params: [SODTO, isSRVUpd, FieldNameValues],
                        onSuccess: $scope.onSubmitSuccess,
                        onFailure: $scope.onSubmitFailure
                    };
                    debugger;
                    u9.callSV(result);
                } else {
                    return;
                }
            });
        };


        //删除按钮
        var onDeleteSOSuccess = function (data) {
            u9.hideLoading();
            var aa = $scope.useIdArr.length;
            var bb = 0;
            for (var i = 0; i < data.length; i++) {
                if (data[i].IsDeleted) {
                    bb += 1;
                }
            }
            ;
            var cc = aa - bb;
            u9.alert("共删除" + aa + "条，成功" + bb + "条,失败" + cc + "条");
            $scope.useIdArr = [];
            $scope.InitOrderlist();
        }

        var onDeleteSOError = function (data) {
            u9.hideLoading();
            u9.alert("删除订单失败");
            $scope.useIdArr = [];
            $scope.InitOrderlist();

        }
        //订单列表删除订单操作
        $scope.orderlistdeleteItem = function () {
            $scope.pushId('userchecked');
            if ($scope.myCount() <= 0) {
                u9.alert('请选中要删除的记录');
                return;
            }

            u9.confirm('确定要删除吗？').then(function (result) {
                if (result) {
                    u9.showLoading();
                    $scope.orderlistcanceloption(); //按钮回复初始化
                    var SODTO = [];
                    //组合数据参数
                    for (var i = 0; i < $scope.useIdArr.length; i++) {
                        //var soid = $scope.SOHeadArr[$scope.useIdArr[i]].ID;
                        var soid = $scope.useIdArr[i];
                        for (k = 0; k < $scope.SOHeadArr.length; k++) {

                            if ($scope.SOHeadArr[k].ID == soid) {
                                var sysversion = $scope.SOHeadArr[k].Sysversion;
                                var item = {
                                    SOID: soid,
                                    SOVersion: sysversion,
                                    ErrorMessage: '',
                                    IsDeleted: true
                                };
                                SODTO.push(item);
                            }
                        }
                    }

                    //调用删除单据服务
                    var jsonData = {
                        name: 'UFIDA.U9.ISV.SM.SOShipAppSV.IDeleteSOSV',
                        params: [SODTO, ''],
                        onSuccess: onDeleteSOSuccess,
                        onFailure: onDeleteSOError
                    };
                    u9.showLoading();
                    u9.callSV(jsonData);
                } else {
                    return;
                }
            });
        }

        //点击取消
        $scope.orderlistcanceloption = function () {
            if ($scope.pagename !== "待发货订单" && $scope.pagename !== "待立账订单") {
                $scope.orderlistToolbtnflag = true;
            }
            $scope.orderlistsubmitbtnflag = false;
            $scope.Orderlistdeletebtnflag = false;
            $scope.orderlistcancelbtnflag = false;
            $scope.checkedFlag = false;
            //$scope.orderlistRoutbtnflag = true;
            $scope.orderlistcancelselected("userchecked");
        }


        //路由事件
        $scope.orderlistrouteoption = function () {
            $scope.orderlistcanceloption(); //按钮回复初始化
            $scope.SOHeadArr.length = 0;
            $scope.temptest = {
                filtervalue: '',
                filterstate: 3
            };
            $scope.orderlistcanceloption();
            $state.go("Home");
            $scope.myFunc();
        }


        $scope.orderlistshowActionsheet = function () {

            $scope.orderlistToolbtnflag = false;
            $scope.orderlistcancelbtnflag = true;
            if ($scope.pagename == "待审核订单") {
                $scope.orderlistsubmitbtnflag = false;
            } else {
                $scope.orderlistsubmitbtnflag = true;
            }

            $scope.Orderlistdeletebtnflag = true;
            $scope.checkedFlag = true;
        };
        //张晓东-控制批量修改功能-结束

        $scope.goCreateOrderLineList = function () {
            //首先判断头是否为空
            if ($scope.sohead.customername == "") {
                u9.alert("请录入订单头信息。");
                return;
            }
            //将头数据收集起来
            $scope.headArr.push({
                docno: $scope.sohead.docno,
                customername: $scope.sohead.customername,
                customercode: $scope.sohead.customercode,
                customerid: $scope.sohead.customerid,
                currencyid: $scope.sohead.currencyid,
                currencyname: $scope.sohead.currencyname,
                currencycode: $scope.sohead.currencycode,
                requiredate: $scope.sohead.requiredate
            });

            $state.go('CreateOrderLineList');
        }

        //方霞--开始

        //控件永远都不显示(料品ID，客户ID，币种，单位)
        $scope.visibile = false;


        //orderheaddetail  按钮控制及事件-----开始
        //编辑按钮
        $scope.orderheaddetaileditclick = function () {
            $scope.orderheaddetaileditflag = false; //编辑显示
            $scope.orderheaddetailcancelflag = true; //取消不显示
            $scope.orderheaddetailaddlineflag = true; //增行不显示
        }
        //取消按钮
        $scope.orderheaddetailcancelclick = function () {
            $scope.orderheaddetailcancelflag = false; //取消不显示
            if ($scope.pagename !== "待发货订单" && $scope.pagename !== "待立账订单") {
                $scope.orderheaddetaileditflag = true; //编辑显示
            }

            $scope.orderheaddetailaddlineflag = false; //增行不显示
        }
        //增行按钮
        $scope.orderheaddetailaddlineclick = function () {
            $scope.orderheaddetailcancelclick(); //按钮回复初始化
            $scope.isfromwhere = "modifyso";
            var index = $scope.INDEX;
            $scope.currencysymbol = $scope.SOHeadArr[index].Currency.Symbol;
            $state.go('SoLine');
        }
        //回退按钮
        $scope.orderheaddetailrouteoption = function () {
            $scope.orderheaddetailcancelclick(); //按钮回复初始化
            $state.go('OrderList');
            $scope.InitOrderlist();
        }
        //进入订单行列表按钮
        $scope.orderheaddetailgetLineList = function () {
            $scope.orderheaddetailcancelclick(); //本页面按钮回复初始化
            if ($scope.pagename !== "待发货订单" && $scope.pagename !== "待立账订单") {
                $scope.OrderLineListcancelclick(); //订单列表画面编辑按钮显示
                $scope.OrderLineListaddlineflag = true;
            } else {
                $scope.OrderLineListeditflag = false;
                $scope.OrderLineListcancelflag = false;
                $scope.OrderLineListaddlineflag = false;
                $scope.OrderLineListdeletelineflag = false;
            }
            $state.go('OrderLineList');
        }
        //orderheaddetail  按钮控制及事件-----结束

        //单据修改方法（订单头明细、订单行列表、订单行明细都会使用）
        $scope.onModifyOrderSuccess = function (data) {
            u9.hideLoading();
            //u9.alert("修改订单成功");
            var index = $scope.INDEX;
            if (data.ModifySO.ID == $scope.SOHeadArr[index].ID) {
                //一条订单即单头 head
                $scope.SOHeadArr[index].Status = data.ModifySO.Status;
                $scope.SOHeadArr[index].DocNo = data.ModifySO.DocNo;
                $scope.SOHeadArr[index].Sysversion = data.ModifySO.Sysversion;
                //交易总金额
                //  var mtotalmoney = data[i].m_totalMoney;
                //客户
                var mcustomer = {
                    ID: data.ModifySO.Customer.ID,
                    Code: data.ModifySO.Customer.Code,
                    Name: data.ModifySO.Customer.Name
                };
                $scope.SOHeadArr[index].Customer = mcustomer;
                //币种
                var mCurrency = {
                    ID: data.ModifySO.Currency.ID,
                    Code: data.ModifySO.Currency.Code,
                    Name: data.ModifySO.Currency.Name,
                    ShortName: data.ModifySO.Currency.Shortname,
                    Symbol: data.ModifySO.Currency.Symbol
                };

                $scope.SOHeadArr[index].Currency = mCurrency;

                //生成订单日期
                var mbusinesDate = ""; //data[i].m_businessDate;

                //增加行数组 tmpsolines 即多行数据
                var tmpsolines = [];

                //价税合计总值
                var tmpTotalMoney = 0;

                //单行--开始
                for (var j = 0; j < data.ModifySO.SOLine.length; j++) {
                    var id = data.ModifySO.SOLine[j].ID;
                    //var mSoline={LineNum:}; 行号
                    var linenum = data.ModifySO.SOLine[j].LineNum;
                    //fangxia_20140902
                    //是否删除标志
                    var DeleteFlag = data.ModifySO.SOLine[j].DeleteFlag
                    //生成料品（Code Name）
                    var iteminfo = {
                        ID: data.ModifySO.SOLine[j].Item.ID,
                        Code: data.ModifySO.SOLine[j].Item.Code,
                        Name: data.ModifySO.SOLine[j].Item.Name
                    };
                    //计价单位
                    var mun = {
                        ID: data.ModifySO.SOLine[j].Unit.ID,
                        Code: data.ModifySO.SOLine[j].Unit.Code,
                        Name: data.ModifySO.SOLine[j].Unit.Name
                    };

                    //数量
                    var mOrderByQtyPU = data.ModifySO.SOLine[j].Amount;

                    //定价
                    var mOrderPriceTC = data.ModifySO.SOLine[j].Price;

                    //价税合计
                    var mTotalMoney = data.ModifySO.SOLine[j].TotalMoney;

                    tmpTotalMoney = tmpTotalMoney + parseFloat(mTotalMoney);
                    //单行中 销售订单行累计信息SOLineSumInfo的“累计出货量”
                    var m_sumShipAmount = data.ModifySO.SOLine[j].SumShipAmount;

                    //单行中 销售订单行累计信息SOLineSumInfo的 已立账数量1  “累计立账数量”(销售单位)
                    var m_sumAccureAmount = data.ModifySO.SOLine[j].SumAccureAmount;

                    //单行中 销售订单行累计信息SOLineSumInfo的累“计立账金额”(交易币种)
                    var m_sumAccureMoney = data.ModifySO.SOLine[j].SumAccureMoney;

                    //单行中 销售订单行累计信息SOLineSumInfo的累计退货扣款金额(交易币种)
                    var m_sumPayMoney = data.ModifySO.SOLine[j].SumPayMoney;

                    //如果行有订单子航 ShipPlanQtyPU
                    var mShipline = [];
                    if (data.ModifySO.SOLine[j].SOShipLineDTO.length > 0) {
                        for (var k = 0; k < data.ModifySO.SOLine[j].SOShipLineDTO.length; k++) {
                            var tempshipline = {
                                ID: data.ModifySO.SOLine[j].SOShipLineDTO[k].ID,
                                SublineNo: data.ModifySO.SOLine[j].SOShipLineDTO[k].DocSubLineNo,
                                RequiredDate: data.ModifySO.SOLine[j].SOShipLineDTO[k].RequiredDate,
                                ShipPlanQtyPU: data.ModifySO.SOLine[j].SOShipLineDTO[k].ShipPlanQtyPU,
                                ShipPlanQtyTU: data.ModifySO.SOLine[j].SOShipLineDTO[k].ShipPlanQtyTU,
                                TUToTBURate: data.ModifySO.SOLine[j].SOShipLineDTO[k].TUToTBURate,
                                ShipPlanQtyTBU: data.ModifySO.SOLine[j].SOShipLineDTO[k].ShipPlanQtyTBU,
                                SOShipLineSumInfo_SumReturnReShipQtyTU: data.ModifySO.SOLine[j].SOShipLineDTO[k].SOShipLineSumInfo_SumReturnReShipQtyTU,
                                SOShipLineSumInfo_ShipTakeQtyTBU: data.ModifySO.SOLine[j].SOShipLineDTO[k].SOShipLineSumInfo_ShipTakeQtyTBU,
                                SOShipLineSumInfo_ShipTakeQtyTU: data.ModifySO.SOLine[j].SOShipLineDTO[k].SOShipLineSumInfo_ShipTakeQtyTU,
                                SOShipLineSumInfo_SumConfirmQtyPU: data.ModifySO.SOLine[j].SOShipLineDTO[k].SOShipLineSumInfo_SumConfirmQtyPU,
                                SOShipLineSumInfo_SumReturnReShipQtyTBU: data.ModifySO.SOLine[j].SOShipLineDTO[k].SOShipLineSumInfo_SumReturnReShipQtyTBU
                            }

                            var mRequireDate = new Date(data.ModifySO.SOLine[j].SOShipLineDTO[k].RequiredDate);
                            if (k == 0) {
                                var monthtemp = '';
                                var today = '';
                                if (parseInt(mRequireDate.getMonth()) + 1 > 9) {
                                    monthtemp = (parseInt(mRequireDate.getMonth()) + 1).toString();
                                } else {

                                    monthtemp = "0" + (parseInt(mRequireDate.getMonth()) + 1).toString();
                                }

                                if (parseInt(mRequireDate.getDate()) > 9) {
                                    today = (parseInt(mRequireDate.getDate())).toString();
                                } else {
                                    today = "0" + (parseInt(mRequireDate.getDate())).toString();
                                }

                                mbusinesDate = mRequireDate.getFullYear() + '-' + monthtemp + '-' + today;

                            }
                            ;

                            mShipline.push(tempshipline);
                        }
                        ;
                    }
                    ;

                    //订单行
                    var tmpsoline = {
                        ID: id,
                        Linenum: linenum,
                        //20140902
                        DeleteFlag: DeleteFlag,
                        ItemInfo: iteminfo,
                        UN: mun,
                        OrderByQtyPU: mOrderByQtyPU,
                        OrderPriceTC: mOrderPriceTC,
                        TotalMoney: mTotalMoney,
                        SumShipAmount: m_sumShipAmount,
                        SumAccureAmount: m_sumAccureAmount,
                        SumAccureMoney: m_sumAccureMoney,
                        SumPayMoney: m_sumPayMoney,
                        RequireDate: mbusinesDate,
                        ShipLine: mShipline
                    };
                    tmpsolines.push(tmpsoline);
                }
                ;
                //单行--结束
                $scope.SOHeadArr[index].TotalMoney = tmpTotalMoney;
                $scope.SOHeadArr[index].BusinesDate = mbusinesDate;
                $scope.SOHeadArr[index].SoLines = tmpsolines;
            }
            ;


            $scope.$apply();
        }

        $scope.removeItem = function (a) {
            for (var i = 0; i < a.length; i++) {
                if (a[i] == "" || typeof(a[i]) == "undefined") {
                    a.splice(i, 1);
                    i = i - 1;
                }
            }
        }
        $scope.onModifyOrderError = function (data) {
            u9.hideLoading();
            // alert("修改订单失败");
            //修改 删除 曾行

            if ($scope.solinecopylist.length > 0) {
                //修改失败：
                $scope.RecoverSolines();
            } else {
                //删除失败：
                for (var i = 0; i < $scope.SOHeadArr[$scope.INDEX].SoLines.length; i++) {
                    $scope.SOHeadArr[$scope.INDEX].SoLines[i].DeleteFlag = false; //删除符号
                }
                ;
            }
            u9.alert("修改订单失败,失败原因:" + data._message);
        }

        $scope.orderheaddetailmodifyChecked = function () {
            var modifysoindex = $scope.INDEX;
            var solineindex = $scope.SoLineDetailINDEX;
            //组装入口参数中行数据
            var soshiplineList = [];
            var solineList = []; //这个是一行的例子
            for (var i = 0; i < $scope.SOHeadArr[modifysoindex].SoLines.length; i++) {

                $scope.Item = {}; //行料品数据
                $scope.Item.Name = $scope.SOHeadArr[modifysoindex].SoLines[i].ItemInfo.Name;
                $scope.Item.Code = $scope.SOHeadArr[modifysoindex].SoLines[i].ItemInfo.Code;
                $scope.Item.ID = $scope.SOHeadArr[modifysoindex].SoLines[i].ItemInfo.ID;
                $scope.Unit = {}; //计价单位
                $scope.Unit.ID = $scope.SOHeadArr[modifysoindex].SoLines[i].UN.ID;

                $scope.LineData = {}; //行数据
                $scope.LineData.ID = $scope.SOHeadArr[modifysoindex].SoLines[i].ID;
                $scope.LineData.LineNum = $scope.SOHeadArr[modifysoindex].SoLines[i].Linenum; //行号
                $scope.LineData.DeleteFlag = $scope.SOHeadArr[modifysoindex].SoLines[i].DeleteFlag; //删除符号
                $scope.LineData.Item = $scope.Item; //料品
                $scope.LineData.Unit = $scope.Unit; //计价单位
                if ($scope.SOHeadArr[modifysoindex].SoLines[i].OrderByQtyPU == "") //数量
                {
                    $scope.LineData.Amount = 0;
                } else {
                    $scope.LineData.Amount = parseFloat($scope.SOHeadArr[modifysoindex].SoLines[i].OrderByQtyPU);
                }
                if ($scope.SOHeadArr[modifysoindex].SoLines[i].OrderPriceTC == "") //单价
                {
                    $scope.LineData.Price = 0;
                } else {
                    $scope.LineData.Price = parseFloat($scope.SOHeadArr[modifysoindex].SoLines[i].OrderPriceTC);
                }


                $scope.soshipline = {}; //一行一子行处理
                $scope.soshipline.RequireDate = $scope.SOHeadArr[modifysoindex].SoLines[i].RequireDate; //交期
                $scope.soshipline.ShipPlanQtyPU = $scope.SOHeadArr[modifysoindex].SoLines[i].OrderByQtyPU; //子行数量
                $scope.soshipline.ID = $scope.SOHeadArr[modifysoindex].SoLines[i].ShipLine[0].ID; //子行数量
                soshiplineList.push($scope.soshipline);

                $scope.LineData.SOShipLineDTO = soshiplineList; //子行
                // $scope.LineData.RequireDate=$scope.lineArr[i].requiredate; //交期  还有问题

                solineList.push($scope.LineData);
                soshiplineList = []; //清空，不然会造成每一行多都多子行
            }
            for (var j = 0; j < $scope.newaddlinelist.length; j++) {

                $scope.Item = {}; //行料品数据
                $scope.Item.Name = $scope.newaddlinelist[j].ItemInfo.Name;
                $scope.Item.Code = $scope.newaddlinelist[j].ItemInfo.Code;
                $scope.Item.ID = $scope.newaddlinelist[j].ItemInfo.ID;
                $scope.Unit = {}; //计价单位
                $scope.Unit.ID = $scope.newaddlinelist[j].UN.ID;

                $scope.LineData = {}; //行数据
                $scope.LineData.ID = $scope.newaddlinelist[j].ID;
                $scope.LineData.LineNum = $scope.newaddlinelist[j].Linenum; //行号
                $scope.LineData.DeleteFlag = $scope.newaddlinelist[j].DeleteFlag; //删除符号
                $scope.LineData.Item = $scope.Item; //料品
                $scope.LineData.Unit = $scope.Unit; //计价单位
                if ($scope.newaddlinelist[j].OrderByQtyPU == "") //数量
                {
                    $scope.LineData.Amount = 0;
                } else {
                    $scope.LineData.Amount = parseFloat($scope.newaddlinelist[j].OrderByQtyPU);
                }
                if ($scope.newaddlinelist[j].OrderPriceTC == "") //单价
                {
                    $scope.LineData.Price = 0;
                } else {
                    $scope.LineData.Price = parseFloat($scope.newaddlinelist[j].OrderPriceTC);
                }


                $scope.soshipline = {}; //一行一子行处理
                $scope.soshipline.RequireDate = $scope.newaddlinelist[j].RequireDate; //交期
                $scope.soshipline.ShipPlanQtyPU = $scope.newaddlinelist[j].OrderByQtyPU; //子行数量
                $scope.soshipline.ID = $scope.newaddlinelist[j].ShipLine[0].ID; //子行数量
                soshiplineList.push($scope.soshipline);

                $scope.LineData.SOShipLineDTO = soshiplineList; //子行
                // $scope.LineData.RequireDate=$scope.lineArr[i].requiredate; //交期  还有问题

                solineList.push($scope.LineData);
                soshiplineList = []; //清空，不然会造成每一行多都多子行
            }
            ;
            $scope.newaddlinelist.length = 0; //清空增行数据
            //组装头数据
            $scope.Customer = {}; //头客户数据
            $scope.Customer.Name = $scope.SOHeadArr[modifysoindex].Customer.Name;
            $scope.Customer.Code = $scope.SOHeadArr[modifysoindex].Customer.Code;
            $scope.Customer.ID = $scope.SOHeadArr[modifysoindex].Customer.ID;
            $scope.Currency = {}; //币种
            $scope.Currency.ID = $scope.SOHeadArr[modifysoindex].Currency.ID;
            $scope.Currency.Code = $scope.SOHeadArr[modifysoindex].Currency.Code;
            $scope.Currency.Name = $scope.SOHeadArr[modifysoindex].Currency.Name;
            $scope.headData = {}; //行料品数据
            $scope.headData.DocNo = $scope.SOHeadArr[modifysoindex].DocNo; //单号
            $scope.headData.Customer = $scope.Customer; //客户
            $scope.headData.Currency = $scope.Currency; //币种
            $scope.headData.Status = $scope.SOHeadArr[modifysoindex].Status; //状态
            $scope.headData.ID = $scope.SOHeadArr[modifysoindex].ID; //ID
            $scope.headData.SOLine = solineList; //行数据
            $scope.queryData = {};
            var queryData = $scope.headData;
            var jsonData = {
                name: 'UFIDA.U9.ISV.SM.IOrderModifyService',
                params: [queryData, ''],
                onSuccess: $scope.onModifyOrderSuccess,
                onFailure: $scope.onModifyOrderError

            };
            u9.showLoading();
            u9.callSV(jsonData);
        }

        //OrderLineList  按钮控制及事件-----开始

        //编辑按钮
        $scope.OrderLineListeditclick = function () {
            $scope.OrderLineListeditflag = false; //编辑不显示
            $scope.OrderLineListcancelflag = true; //取消显示
            // $scope.OrderLineListaddlineflag = true; //增行显示
            $scope.OrderLineListdeletelineflag = true; //删行显示
            $scope.OrderLineListcheckedflag = true; //复选框显示
        }
        //取消按钮
        $scope.OrderLineListcancelclick = function () {
            $scope.OrderLineListcancelflag = false; //取消不显示
            if ($scope.pagename !== "待发货订单" && $scope.pagename !== "待立账订单") {
                $scope.OrderLineListeditflag = true; //编辑显示
                $scope.OrderLineListaddlineflag = true; //增行显示
            }
            $scope.OrderLineListaddlineflag = false; //增行不显示
            $scope.OrderLineListdeletelineflag = false; //删行不显示
            $scope.OrderLineListcheckedflag = false; //复选框显示
            $scope.orderlistcancelselected("usercheckedline");
        }
        //回退按钮
        $scope.OrderLineListrouteoption = function () {
            $scope.OrderLineListcancelclick(); //按钮回复初始化
            //fangxia33.24
            //$state.go('OrderHeadDetail');
            $state.go('OrderList');
            $scope.InitOrderlist();
        }
        //进入订单行列表按钮
        $scope.sendsolinelistindex = function (index) {
            $scope.myList = $scope.SOHeadArr[$scope.tempIndex].SoLines;
            //赋值所有订单行数据
            $scope.CopySOLine();
            $scope.OrderLineListcancelclick(); //按钮回复初始化
            if ($scope.pagename !== "待发货订单" && $scope.pagename !== "待立账订单") {
                $scope.SoLineDetaileditflag = true; //订单行明细编辑按钮显示
                $scope.SoLineDetailbtnEnabled = false;
                $scope.SoLineDetailcancelflag = false;
                $scope.SoLineDetailSaveflag = false;
                $scope.OrderLineListaddlineflag = true; //增行显示

            } else {
                $scope.SoLineDetaileditflag = false;
                $scope.SoLineDetailbtnEnabled = false;
                $scope.SoLineDetailcancelflag = false;
                $scope.SoLineDetailSaveflag = false;
                $scope.OrderLineListaddlineflag = false; //增行不显示
            }
            $state.go('SoLineDetail');
            $scope.linelistindex = index;
            $scope.SoLineDetailINDEX = index;
            $scope.initSubline = true;
            if (index == 0) {
                $scope.slideIndex = 0;
            }
            ;
        }
        //增行按钮
        $scope.OrderLineListaddlineclick = function () {
            $scope.OrderLineListcancelclick(); //按钮回复初始化
            $scope.isfromwhere = "modifyso";
            $state.go('SoLine');
        }


        //删行按钮
        $scope.deleteindex = []; //全局变量
        $scope.OrderLineListdeletelineclick = function () {
            var deleteline = document.getElementsByName("usercheckedline");
            for (i = 0; i < deleteline.length; i++) {
                if (deleteline[i].checked == true) {
                    var soindex = $scope.INDEX;
                    $scope.SOHeadArr[soindex].SoLines[i].DeleteFlag = true;
                    $scope.deleteindex.push(i);
                }
            }
            if ($scope.deleteindex.length == 0) {
                u9.alert("请选中要删除的记录");
                $scope.deleteindex = [];
                return;
            }

            u9.confirm('确定要删除吗？', function (result) {
                if (result) {
                    $scope.OrderLineListcancelclick(); //按钮回复初始化
                    $scope.orderheaddetailmodifyChecked(); //调用修改服务
                    u9.showLoading();
                    $scope.deleteindex = [];
                } else {
                    $scope.deleteindex = [];
                    return;
                }
            })
        }

        //OrderLineList  按钮控制及事件-----结束


        //SoLineDetail 按钮控制-----开始

        $scope.solinecopylist = [];
        //备份数据源
        $scope.CopySOLine = function () {
            $scope.solinecopylist.length = 0;

            for (var i = 0; i < $scope.myList.length; i++) {
                var tmpitemInfo = {
                    Code: $scope.myList[i].ItemInfo.Code,
                    Name: $scope.myList[i].ItemInfo.Name
                }
                var solinecopy = {
                    ItemInfo: tmpitemInfo,
                    OrderByQtyPU: $scope.myList[i].OrderByQtyPU,
                    OrderPriceTC: $scope.myList[i].OrderPriceTC,
                    RequireDate: $scope.myList[i].RequireDate,
                    TotalMoney: $scope.myList[i].TotalMoney
                }
                $scope.solinecopylist.push(solinecopy);
            }
            ;
        }

        $scope.RecoverSolines = function () {
            if ($scope.solinecopylist.length > 0) {
                for (var i = 0; i < $scope.solinecopylist.length; i++) {
                    $scope.myList[i].TotalMoney = $scope.solinecopylist[i].TotalMoney;
                    $scope.myList[i].RequireDate = $scope.solinecopylist[i].RequireDate;
                    $scope.myList[i].OrderPriceTC = $scope.solinecopylist[i].OrderPriceTC;
                    $scope.myList[i].OrderByQtyPU = $scope.solinecopylist[i].OrderByQtyPU;
                    $scope.myList[i].ItemInfo.Code = $scope.solinecopylist[i].ItemInfo.Code;
                    $scope.myList[i].ItemInfo.Name = $scope.solinecopylist[i].ItemInfo.Name;
                }
                ;
            }
            ;
        }

        //编辑按钮
        $scope.SOLineDetailItemArrowFlag2 = true;
        $scope.SoLineDetaileditclick = function () {
            $scope.SoLineDetaileditflag = false; //编辑不显示
            $scope.SoLineDetailcancelflag = true; //取消显示
            $scope.SoLineDetailSaveflag = true; //保存显示
            $scope.SOLineDetailItemArrowFlag = true;
            $scope.SOLineDetailItemArrowFlag2 = false;
        }
        //取消按钮
        $scope.SoLineDetailcancelclick = function () {
            $scope.SoLineDetailcancelflag = false; //取消不显示
            if ($scope.pagename !== "待发货订单" && $scope.pagename !== "待立账订单") {
                $scope.SoLineDetaileditflag = true; //编辑显示
                $scope.SOLineDetailItemArrowFlag2 = true;
            } else {
                $scope.SoLineDetaileditflag = false;
                $scope.SOLineDetailItemArrowFlag2 = true;
            }
            $scope.SoLineDetailSaveflag = false; //保存不显示
            $scope.RecoverSolines();
            $scope.SOLineDetailItemArrowFlag = false;
            $scope.SOLineDetailItemArrowFlag2 = true;
        }
        //回退按钮
        $scope.SoLineDetailrouteoption = function () {
            $scope.SoLineDetailcancelclick(); //按钮回复初始化
            //单页值恢复到原值
            //$scope.RecoverSolines();
            //var tempindex = $scope.INDEX;
            //var tempsolineindex = $scope.SoLineDetailINDEX;
            ////单价、数量由字符串类型转换成数字类型
            //$scope.SOHeadArr[tempindex].SoLines[tempsolineindex].OrderByQtyPU = parseFloat($scope.SOHeadArr[tempindex].SoLines[tempsolineindex].OrderByQtyPU);
            //$scope.SOHeadArr[tempindex].SoLines[tempsolineindex].OrderPriceTC = parseFloat($scope.SOHeadArr[tempindex].SoLines[tempsolineindex].OrderPriceTC);
            $state.go("OrderLineList");
            var aa = $scope.SOHeadArr;
        }
        //保存方法
        $scope.SoLineDetailSaveclick = function () {
            //$scope.SoLineDetailcancelclick(); //按钮回复初始化
            $scope.SoLineDetailcancelflag = false; //取消不显示
            $scope.SOLineDetailItemArrowFlag = false; //料品选择不显示
            $scope.SOLineDetailItemArrowFlag2 = true; //数量单价不可编辑
            if ($scope.pagename !== "待发货订单" && $scope.pagename !== "待立账订单") {
                $scope.SoLineDetaileditflag = true; //编辑显示
            }
            $scope.SoLineDetailSaveflag = false; //保存不显示
            $scope.orderheaddetailmodifyChecked(); //调用保存方法
            u9.showLoading();
        }
        //料品链接
        $scope.SoLineDetailModifyItem = function () {
            $scope.modifyitemisfrom = "SoLineDetail";
            $scope.GoItemPage();
        }
        //SoLineDetail 按钮控制-----结束

        $scope.SoLineGoItemPage = function () {
            $scope.modifyitemisfrom = "CreateSoLine";
            $scope.GoItemPage();
        }
        //清空头、行数据(初始化头、行数据)
        $scope.clearSOAllData = function () {
            $scope.soline = {
                doclineno: 0,
                itemcode: "",
                itmename: "",
                itemid: "",
                puid: 0,
                pucode: "",
                puname: "",
                presion: "",
                orderbyqty: 0,
                price: 0,
                requiredate: $scope.testtime,
                totalmoney: 0
            };
            $scope.sohead = {
                docno: "",
                customername: "",
                customercode: "",
                customerid: 0,
                currencyid: 0,
                currencycode: "",
                currencyname: "",
                currencycymbol: "",
                requiredate: $scope.testtime
            };
            $scope.linecount = 0;
            $scope.lineArr = []; //清空行列表数据
        }
        //下单按钮
        $scope.goSoHead = function () {
            $scope.clearSOAllData();
            $state.go('SoHead');
        }
        //创建订单头回退事件
        $scope.soheadgoback = function () {
            $scope.clearSOAllData();
            $state.go('Home');
        }


        //录入行时通过单价和数量自动计算价税合计
        $scope.qtytotalmoney = function () {
            $scope.soline.orderbyqty = "";
        }


        $scope.pricetotalmoney = function () {
            $scope.soline.price = "";
        }

        //录入行时通过单价和数量自动计算价税合计
        $scope.calqtytotalmoney = function () {
            //var RegExpression1=new RegExp("^[0-9]+$");
            //if (!RegExpression1.test($scope.soline.orderbyqty)) {alert("请输入大于或等于0的整数")};
            //var RegExpression2=new RegExp("^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,2})?$");
            if ($scope.soline.orderbyqty != 0 && $scope.soline.price != 0) {
                $scope.soline.totalmoney = ($scope.soline.price * $scope.soline.orderbyqty).toFixed(2);
            }
        }

        $scope.solinedetailcalqtytotalmoney = function () {
            if (parseFloat($scope.myList[$scope.slideIndex].OrderByQtyPU, 10) != 0 && parseFloat($scope.myList[$scope.slideIndex].OrderPriceTC, 10) != 0) {
                $scope.myList[$scope.slideIndex].TotalMoney = (parseFloat($scope.myList[$scope.slideIndex].OrderByQtyPU, 10) * parseFloat($scope.myList[$scope.slideIndex].OrderPriceTC, 10)).toFixed(2);
            }
            ;

        }

        $scope.calpricetotalmoney = function () {
            //var RegExpression2=new RegExp("^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,2})?$");
            //var  RegExpression2=new RegExp("^\d+(.?\d{1,2})?$");
            //var  RegExpression2=new RegExp("^\d{0,8}\.{0,1}(\d{1,2})?$");
            //var  RegExpression2=new RegExp("\d{1,}\.\d{2}$");
            //var  RegExpression2=new RegExp("^\d+(\.\d{1,2})?$");
            //var  RegExpression2=new RegExp("[0-9]+\.?[0-9]{0,2}");
            //var  RegExpression2=new RegExp("\d+(.)\d{0,2}");
            //if (!RegExpression2.test($scope.soline.price)) {alert("请输入不超过两位小数的浮点数")};
            if ($scope.soline.orderbyqty != 0 && $scope.soline.price != 0) {
                $scope.soline.totalmoney = ($scope.soline.price * $scope.soline.orderbyqty).toFixed(2);
            }
        }


        //新增行画面--开始
        //收集行数据
        $scope.colectsolinedata = function () {
            //创建订单进入
            if ($scope.isfromwhere == "SoHead") {
                //校验：行数据不为空时
                // if ($scope.soline.itemcode !== "" && $scope.soline.orderbyqty !== 0 && $scope.soline.price !== 0) {
                if ($scope.soline.itemcode !== "") {
                    if (parseInt($scope.soline.orderbyqty) <= 0 || $scope.soline.orderbyqty == "") {
                        u9.alert("请录入料品数量");
                        return;
                    } else {
                        $scope.lineArr.push({
                            doclineno: $scope.soline.doclineno,
                            itemcode: $scope.soline.itemcode,
                            itemid: $scope.soline.itemid,
                            itemname: $scope.soline.itemname,
                            puname: $scope.soline.puname,
                            pucode: $scope.soline.pucode,
                            puid: $scope.soline.puid,
                            presion: $scope.soline.presion,
                            orderbyqty: $scope.soline.orderbyqty,
                            price: $scope.soline.price,
                            requiredate: $scope.soline.requiredate,
                            currencysymbol: $scope.currencysymbol,
                            totalmoney: $scope.soline.totalmoney
                        });
                    }
                }

            }
            //修改订单进入
            else {
                //收集数据，添加到SOHeadArr[tempIndex].SoLines中
                if ($scope.soline.itemcode !== "") {
                    if (parseInt($scope.soline.orderbyqty) <= 0 || $scope.soline.orderbyqty == "") {
                        u9.alert("请录入料品数量");
                        return;
                    } else {

                        var index = $scope.INDEX; //订单索引
                        var newlineindex = $scope.SOHeadArr[index].SoLines.length; //新增行的存储的索引

                        var newlinedoclineno = $scope.SOHeadArr[index].SoLines[newlineindex - 1].Linenum + 10; //新增行行号为原最好行号加10

                        //先创建行存储数据
                        $scope.SoShipLine = {}; //子行
                        $scope.SoShipLine.RequireDate = $scope.soline.requiredate; //子行交期
                        $scope.SoShipLine.ShipPlanQtyPU = $scope.soline.orderbyqty; //子行数量
                        $scope.Item = {}; //行料品数据
                        $scope.Item.Name = $scope.soline.itemname;
                        $scope.Item.Code = $scope.soline.itemcode;
                        $scope.Item.ID = $scope.soline.itemid;
                        $scope.Unit = {}; //计价单位
                        $scope.Unit.ID = $scope.soline.puid;
                        $scope.Unit.Code = $scope.soline.puncode;
                        $scope.Unit.Name = $scope.soline.puname;

                        var newaddsoline = [];
                        var newaddsolineinfo = {};
                        newaddsolineinfo.Linenum = newlinedoclineno;
                        newaddsolineinfo.ItemInfo = {};
                        newaddsolineinfo.ItemInfo.ID = $scope.soline.itemid;
                        newaddsolineinfo.ItemInfo.Code = $scope.soline.itemcode;
                        newaddsolineinfo.ItemInfo.Name = $scope.soline.itemname;
                        newaddsolineinfo.UN = {};
                        newaddsolineinfo.UN.ID = $scope.soline.puid;
                        newaddsolineinfo.UN.Code = $scope.soline.puncode;
                        newaddsolineinfo.UN.Name = $scope.soline.puname;
                        newaddsolineinfo.OrderByQtyPU = $scope.soline.orderbyqty;
                        newaddsolineinfo.OrderPriceTC = $scope.soline.price;
                        newaddsolineinfo.TotalMoney = $scope.soline.totalmoney;
                        newaddsolineinfo.SumShipAmount = 0;
                        newaddsolineinfo.SumAccureAmount = 0;
                        newaddsolineinfo.SumAccureMoney = 0;
                        newaddsolineinfo.SumPayMoney = 0;
                        newaddsolineinfo.RequireDate = $scope.soline.requiredate;
                        soshiplineList = [];
                        soshipline = {}; //子行
                        soshipline.RequireDate = $scope.soline.requiredate; //交期
                        soshipline.ShipPlanQtyPU = $scope.soline.orderbyqty; //子行数量
                        soshiplineList.push(soshipline);
                        newaddsolineinfo.ShipLine = soshiplineList;

                        $scope.SOHeadArr[index].SoLines.push(newaddsolineinfo);
                    }
                } else {
                    u9.alert("请录入料品、料品数量信息。");
                    return;
                }
            }
        }
        //增行按钮
        $scope.SoLineAddLine = function () {
            //收集数据
            if ($scope.isfromwhere == "SoHead") {
                if ($scope.soline.itemcode !== "") {
                    if (parseInt($scope.soline.orderbyqty) <= 0 || $scope.soline.orderbyqty == "") {
                        u9.alert("请录入料品数量");
                        return;
                    } else {
                        $scope.lineArr.push({
                            doclineno: $scope.soline.doclineno,
                            itemcode: $scope.soline.itemcode,
                            itemid: $scope.soline.itemid,
                            itemname: $scope.soline.itemname,
                            puname: $scope.soline.puname,
                            pucode: $scope.soline.pucode,
                            puid: $scope.soline.puid,
                            presion: $scope.soline.presion,
                            orderbyqty: $scope.soline.orderbyqty,
                            price: $scope.soline.price,
                            requiredate: $scope.soline.requiredate,
                            currencysymbol: $scope.currencysymbol,
                            totalmoney: $scope.soline.totalmoney
                        });
                        $scope.clearInput(); //清空数据 放到收集数据中处理
                        $scope.linecount += 1; //行数量加1
                        $scope.soline.doclineno = $scope.linecount * 10;
                        //$scope.linecount = $scope.soline.doclineno / 10;
                    }
                } else {
                    u9.alert("请录入料品、料品数量信息。");
                    return;
                }

            } else {
                $scope.colectsolinedata(); //收集行数据
                $scope.clearInput(); //清空数据

            }

        }
        //回退按钮（将行数据收集起来，并清空录入数据）
        $scope.lineArr = [];
        $scope.solinegoback = function () {
            //创建订单进入
            if ($scope.isfromwhere == "SoHead") {
                if ($scope.soline.itemcode !== "") {
                    if (parseInt($scope.soline.orderbyqty) <= 0 || $scope.soline.orderbyqty == "") {
                        u9.alert("请录入料品数量");
                        return;
                    } else {
                        //对于已有的行号不再添加数据（保存失败后在回退到头画面）
                        if ($scope.lineArr.length == 0) {
                            $scope.lineArr.push({
                                doclineno: $scope.soline.doclineno,
                                itemcode: $scope.soline.itemcode,
                                itemid: $scope.soline.itemid,
                                itemname: $scope.soline.itemname,
                                puname: $scope.soline.puname,
                                pucode: $scope.soline.pucode,
                                puid: $scope.soline.puid,
                                presion: $scope.soline.presion,
                                orderbyqty: $scope.soline.orderbyqty,
                                price: $scope.soline.price,
                                requiredate: $scope.soline.requiredate,
                                currencysymbol: $scope.currencysymbol,
                                totalmoney: $scope.soline.totalmoney
                            });
                        } else {
                            for (var i = $scope.lineArr.length - 1; i >= 0; i--) {
                                if ($scope.lineArr[i].doclineno == $scope.soline.doclineno) {
                                    $scope.clearInput(); //清空数据 放到收集数据中处理;
                                    $state.go('SoHead');
                                    $scope.sohead.push($scope.sohead);
                                } else {
                                    $scope.lineArr.push({
                                        doclineno: $scope.soline.doclineno,
                                        itemcode: $scope.soline.itemcode,
                                        itemid: $scope.soline.itemid,
                                        itemname: $scope.soline.itemname,
                                        puname: $scope.soline.puname,
                                        pucode: $scope.soline.pucode,
                                        puid: $scope.soline.puid,
                                        presion: $scope.soline.presion,
                                        orderbyqty: $scope.soline.orderbyqty,
                                        price: $scope.soline.price,
                                        requiredate: $scope.soline.requiredate,
                                        currencysymbol: $scope.currencysymbol,
                                        totalmoney: $scope.soline.totalmoney
                                    });
                                }
                            }
                            ;

                        }
                        $scope.clearInput(); //清空数据 放到收集数据中处理
                        $scope.soline.doclineno = ($scope.linecount + 1) * 10;
                        //$scope.linecount = $scope.soline.doclineno / 10;
                        $state.go('SoHead');
                        $scope.sohead.push($scope.sohead);
                    }
                } else {
                    $scope.linecount = $scope.linecount - 1;
                    $state.go('SoHead');
                    $scope.sohead.push($scope.sohead);
                }
            }
            //对已有订单增行
            else {
                if ($scope.soline.itemcode !== "") {
                    if (parseInt($scope.soline.orderbyqty) <= 0 || $scope.soline.orderbyqty == "") {
                        u9.alert("请录入料品数量");
                        return;
                    } else {

                        var index = $scope.INDEX; //订单索引
                        var newlineindex = $scope.SOHeadArr[index].SoLines.length; //新增行的存储的索引

                        var newlinedoclineno = $scope.SOHeadArr[index].SoLines[newlineindex - 1].Linenum + 10; //新增行行号为原最好行号加10

                        //先创建行存储数据
                        $scope.SoShipLine = {}; //子行
                        $scope.SoShipLine.RequireDate = $scope.soline.requiredate; //子行交期
                        $scope.SoShipLine.ShipPlanQtyPU = $scope.soline.orderbyqty; //子行数量
                        $scope.Item = {}; //行料品数据
                        $scope.Item.Name = $scope.soline.itemname;
                        $scope.Item.Code = $scope.soline.itemcode;
                        $scope.Item.ID = $scope.soline.itemid;
                        $scope.Unit = {}; //计价单位
                        $scope.Unit.ID = $scope.soline.puid;
                        $scope.Unit.Code = $scope.soline.puncode;
                        $scope.Unit.Name = $scope.soline.puname;

                        var newaddsoline = [];
                        var newaddsolineinfo = {};
                        newaddsolineinfo.Linenum = newlinedoclineno;
                        newaddsolineinfo.ItemInfo = {};
                        newaddsolineinfo.ItemInfo.ID = $scope.soline.itemid;
                        newaddsolineinfo.ItemInfo.Code = $scope.soline.itemcode;
                        newaddsolineinfo.ItemInfo.Name = $scope.soline.itemname;
                        newaddsolineinfo.UN = {};
                        newaddsolineinfo.UN.ID = $scope.soline.puid;
                        newaddsolineinfo.UN.Code = $scope.soline.puncode;
                        newaddsolineinfo.UN.Name = $scope.soline.puname;
                        newaddsolineinfo.OrderByQtyPU = $scope.soline.orderbyqty;
                        newaddsolineinfo.OrderPriceTC = $scope.soline.price;
                        newaddsolineinfo.TotalMoney = $scope.soline.totalmoney;
                        newaddsolineinfo.SumShipAmount = 0;
                        newaddsolineinfo.SumAccureAmount = 0;
                        newaddsolineinfo.SumAccureMoney = 0;
                        newaddsolineinfo.SumPayMoney = 0;
                        newaddsolineinfo.RequireDate = $scope.soline.requiredate;
                        soshiplineList = [];
                        soshipline = {}; //子行
                        soshipline.RequireDate = $scope.soline.requiredate; //交期
                        soshipline.ShipPlanQtyPU = $scope.soline.orderbyqty; //子行数量
                        soshiplineList.push(soshipline);
                        newaddsolineinfo.ShipLine = soshiplineList;

                        $scope.SOHeadArr[index].SoLines.push(newaddsolineinfo);
                    }
                    $scope.clearInput(); //清空数据
                    $scope.orderheaddetailmodifyChecked(); //调用修改服务
                    $scope.OrderLineListeditflag = true;
                    $state.go('OrderLineList');
                    u9.showLoading();
                } else {
                    $scope.OrderLineListeditflag = true;
                    $state.go('OrderLineList');
                }

            }
        }
        //取消操作
        $scope.solinecanceloption = function () {
            //创建订单进入
            if ($scope.isfromwhere == "SoHead") {
                $scope.clearInput();
                $scope.soline.doclineno = 0;
                $scope.linecount = $scope.linecount - 1;
                //$state.go('SoHead');
                $state.go('CreateOrderLineList');
            }
            //修改订单进入
            else {
                $scope.clearInput();
                $scope.OrderLineListeditflag = true;
                $state.go('OrderLineList');
            }
        }
        //保存操作
        $scope.newaddlinelist = [];
        $scope.SoLineconfirmCreateOrder = function () {
            if ($scope.isfromwhere == "SoHead") {
                if ($scope.soline.itemcode !== "") {
                    if (parseInt($scope.soline.orderbyqty) <= 0 || $scope.soline.orderbyqty == "") {
                        u9.alert("请录入料品数量");
                        return;
                    } else {
                        $scope.lineArr.push({
                            doclineno: $scope.soline.doclineno,
                            itemcode: $scope.soline.itemcode,
                            itemid: $scope.soline.itemid,
                            itemname: $scope.soline.itemname,
                            puname: $scope.soline.puname,
                            pucode: $scope.soline.pucode,
                            puid: $scope.soline.puid,
                            presion: $scope.soline.presion,
                            orderbyqty: $scope.soline.orderbyqty,
                            price: $scope.soline.price,
                            requiredate: $scope.soline.requiredate,
                            currencysymbol: $scope.currencysymbol,
                            totalmoney: $scope.soline.totalmoney
                        });
                        // $scope.linecount = $scope.linecount +1;
                    }
                }
                if ($scope.lineArr.length > 0) //当行有数据时再调用创建订单服务
                {
                    $scope.confirmCreateOrder();
                    u9.showLoading();
                } else {
                    u9.alert("请录入订单行信息");
                    return;
                }
            } else {
                if ($scope.soline.itemcode !== "") {
                    if (parseInt($scope.soline.orderbyqty) <= 0 || $scope.soline.orderbyqty == "") {
                        u9.alert("请录入料品数量");
                        return;
                    } else {

                        var index = $scope.INDEX; //订单索引
                        var newlineindex = $scope.SOHeadArr[index].SoLines.length; //新增行的存储的索引

                        var newlinedoclineno = $scope.SOHeadArr[index].SoLines[newlineindex - 1].Linenum + 10; //新增行行号为原最好行号加10

                        //先创建行存储数据
                        $scope.SoShipLine = {}; //子行
                        $scope.SoShipLine.RequireDate = $scope.soline.requiredate; //子行交期
                        $scope.SoShipLine.ShipPlanQtyPU = $scope.soline.orderbyqty; //子行数量
                        $scope.Item = {}; //行料品数据
                        $scope.Item.Name = $scope.soline.itemname;
                        $scope.Item.Code = $scope.soline.itemcode;
                        $scope.Item.ID = $scope.soline.itemid;
                        $scope.Unit = {}; //计价单位
                        $scope.Unit.ID = $scope.soline.puid;
                        $scope.Unit.Code = $scope.soline.puncode;
                        $scope.Unit.Name = $scope.soline.puname;

                        var newaddsoline = [];
                        var newaddsolineinfo = {};
                        newaddsolineinfo.Linenum = newlinedoclineno;
                        newaddsolineinfo.ItemInfo = {};
                        newaddsolineinfo.ItemInfo.ID = $scope.soline.itemid;
                        newaddsolineinfo.ItemInfo.Code = $scope.soline.itemcode;
                        newaddsolineinfo.ItemInfo.Name = $scope.soline.itemname;
                        newaddsolineinfo.UN = {};
                        newaddsolineinfo.UN.ID = $scope.soline.puid;
                        newaddsolineinfo.UN.Code = $scope.soline.puncode;
                        newaddsolineinfo.UN.Name = $scope.soline.puname;
                        newaddsolineinfo.OrderByQtyPU = $scope.soline.orderbyqty;
                        newaddsolineinfo.OrderPriceTC = $scope.soline.price;
                        newaddsolineinfo.TotalMoney = $scope.soline.totalmoney;
                        newaddsolineinfo.SumShipAmount = 0;
                        newaddsolineinfo.SumAccureAmount = 0;
                        newaddsolineinfo.SumAccureMoney = 0;
                        newaddsolineinfo.SumPayMoney = 0;
                        newaddsolineinfo.RequireDate = $scope.soline.requiredate;
                        soshiplineList = [];
                        soshipline = {}; //子行
                        soshipline.RequireDate = $scope.soline.requiredate; //交期
                        soshipline.ShipPlanQtyPU = $scope.soline.orderbyqty; //子行数量
                        soshiplineList.push(soshipline);
                        newaddsolineinfo.ShipLine = soshiplineList;

                        // $scope.newaddlinelist = [];
                        $scope.newaddlinelist.push(newaddsolineinfo);

                        // $scope.SOHeadArr[index].SoLines.push(newaddsolineinfo);
                    }
                    $scope.clearInput(); //清空数据
                    $scope.orderheaddetailmodifyChecked(); //调用修改服务
                    $scope.OrderLineListeditflag = true;
                    $state.go('OrderLineList');
                    u9.showLoading();
                } else {
                    u9.alert("请录入料品、料品数量信息。");
                    return;
                }
            }

        }
        //新增行画面--结束


        $scope.headArr = [];
        //计算行数、设置行号
        $scope.linecount = 0;
        $scope.goLine = function () {
            //首先判断头是否为空
            if ($scope.sohead.customername == "") {
                u9.alert("请录入订单头信息。");
                return;
            }
            //将头数据收集起来
            $scope.headArr.push({
                docno: $scope.sohead.docno,
                customername: $scope.sohead.customername,
                customercode: $scope.sohead.customercode,
                customerid: $scope.sohead.customerid,
                currencyid: $scope.sohead.currencyid,
                currencyname: $scope.sohead.currencyname,
                currencycode: $scope.sohead.currencycode,
                requiredate: $scope.sohead.requiredate
            });
            $scope.soline.doclineno = ($scope.linecount + 1) * 10;
            $scope.isfromwhere = "SoHead";
            $scope.currencysymbol = $scope.sohead.currencysymbol;
            $state.go('SoLine');
            $scope.linecount = $scope.soline.doclineno / 10;
        }

        //行列表数据（录行后查看数据）


        //服务调用结果
        $scope.onCreateOrderSuccess = function () {
            u9.hideLoading();
            //u9.alert("创建订单成功");
            $scope.soheadgoback();
            $state.go("Home");
            $scope.myFunc();
        }

        $scope.onCreateOrderError = function (data) {
            u9.hideLoading();
            u9.alert("创建订单失败,失败原因:" + data._message);
        }

        //创建订单事件（调用生单服务）
        $scope.confirmCreateOrder = function () {

            var soshiplineList = [];
            var solineList = [];

            //组装入口参数中行数据
            if ($scope.headArr.length == 0) {

                u9.alert("请录入订单头信息。");
                return;
            }
            if ($scope.lineArr.length == 0) {

                u9.alert("请录入订单行信息。");
                return;
            }
            for (var i = 0; i < $scope.lineArr.length; i++) {

                $scope.Item = {}; //行料品数据
                $scope.Item.Name = $scope.lineArr[i].itemname;
                $scope.Item.Code = $scope.lineArr[i].itemcode;
                if ($scope.lineArr[i].itemid !== "" && $scope.lineArr[i].itemid !== null) {

                    $scope.Item.ID = parseInt($scope.lineArr[i].itemid);
                } else {
                    $scope.Item.ID = -1;
                }
                $scope.Unit = {}; //计价单位
                if ($scope.lineArr[i].puid !== "") {

                    $scope.Unit.ID = parseInt($scope.lineArr[i].puid);
                } else {
                    $scope.Unit.ID = -1;
                }
                // $scope.Unit.ID=parseInt($scope.lineArr[i].puid);
                $scope.Unit.Code = $scope.lineArr[i].pucode;
                $scope.Unit.Name = $scope.lineArr[i].puname;

                $scope.LineData = {}; //行数据
                $scope.LineData.LineNum = $scope.lineArr[i].doclineno; //行号
                $scope.LineData.Item = $scope.Item; //料品
                $scope.LineData.Unit = $scope.Unit; //计价单位
                $scope.LineData.Amount = $scope.lineArr[i].orderbyqty; //数量
                $scope.LineData.Price = $scope.lineArr[i].price; //单价

                //一行一子行处理
                $scope.soshipline = {}; //子行
                //$scope.soshipline.RequiredDate = new Date($scope.lineArr[i].requiredate); //交期
                $scope.soshipline.ShipPlanQtyPU = $scope.lineArr[i].orderbyqty; //子行数量
                soshiplineList.push($scope.soshipline);

                $scope.LineData.SOShipLineDTO = soshiplineList; //子行
                solineList.push($scope.LineData);
                soshiplineList = []; //清空，不然会造成每一行多都多子行
            }

            //组装头数据
            $scope.Customer = {}; //头客户数据

            $scope.Customer.Name = $scope.headArr[0].customername;
            $scope.Customer.Code = $scope.headArr[0].customercode;
            if ($scope.headArr[0].customerid !== "" && $scope.headArr[0].customerid !== null) {

                $scope.Customer.ID = parseInt($scope.headArr[0].customerid);
            } else {

                $scope.Customer.ID = -1;
            }
            $scope.Currency = {}; //币种
            if ($scope.headArr[0].currencyid !== "" && $scope.headArr[0].currencyid !== null) {

                $scope.Currency.ID = parseInt($scope.headArr[0].currencyid);
            } else {

                $scope.Currency.ID = -1;
            }
            //$scope.Currency.ID=parseInt($scope.headArr[0].currencyid);
            $scope.Currency.Code = $scope.headArr[0].currencycode;
            $scope.Currency.Name = $scope.headArr[0].currencyname;

            $scope.headData = {}; //行料品数据
            $scope.headData.DocNo = $scope.headArr[0].docno; //单号
            //$scope.headData.DocNo = 'SO201509100008'; //单号
            $scope.headData.Customer = $scope.Customer; //客户
            $scope.headData.Currency = $scope.Currency; //币种
            $scope.headData.Status = "1"; //状态
            $scope.headData.SOLine = solineList; //行数据

            $scope.queryData = {};
            var queryData = $scope.headData;
            var jsonData = {
                name: 'UFIDA.U9.ISV.SM.IOrderCreateService',
                params: [queryData, ''],
                onSuccess: $scope.onCreateOrderSuccess,
                onFailure: $scope.onCreateOrderError

            };
            u9.showLoading();
            u9.callSVAlone(jsonData);

        }


        //获取当前时间
        var now = new Date();

        $scope.lineArr = [];

        //清空行输入数据
        $scope.clearInput = function () {
            $scope.soline.itemcode = "";
            $scope.soline.itemname = "";
            $scope.soline.itemid = 0;
            $scope.soline.puid = 0;
            $scope.soline.pucode = "";
            $scope.soline.puname = "";
            $scope.soline.presion = 0;
            $scope.soline.orderbyqty = 0;
            $scope.soline.price = 0;
            $scope.soline.requiredate = $scope.testtime;
            $scope.soline.totalmoney = 0;

        };


        var testtime = new Date();
        //var  testtime=new Date('2000.01.01'),
        var myyear = testtime.getFullYear();
        var mymonth = testtime.getMonth() + 1;
        var myweekday = testtime.getDate();

        if (mymonth < 10) {
            mymonth = "0" + mymonth;
        }
        if (myweekday < 10) {
            myweekday = "0" + myweekday;
        }
        $scope.testtime = myyear + "-" + mymonth + "-" + myweekday;

        //初始化头、行数据
        $scope.soline = {
            doclineno: 0,
            itemcode: "",
            itmename: "",
            itemid: 0,
            puid: 0,
            pucode: "",
            puname: "",
            presion: 0,
            orderbyqty: 0,
            price: 0,
            requiredate: $scope.testtime,
            totalmoney: 0
        };
        $scope.sohead = {
            docno: "",
            customername: "",
            customercode: "",
            customerid: 0,
            currencyid: 0,
            currencycode: "",
            currencyname: "",
            currencysymbol: "",
            requiredate: $scope.testtime
        };

        //CreateOrderLineList 按钮控制-----开始
        //回退按钮
        $scope.CreateOrderLineListrouteoption = function () {
            $state.go('SoHead');
        }

        //增行按钮
        $scope.CreateOrderLineListaddlineclick = function () {
            $scope.soline.doclineno = ($scope.linecount + 1) * 10;
            //$scope.currencysymbol = $scope.sohead.currencysymbol;
            $scope.linecount = $scope.soline.doclineno / 10;
            $scope.isfromwhere = "SoHead";
            $state.go('SoLine');
        }
        //删行按钮
        $scope.CreateOrderLineListdeletelineclick = function () {

            u9.confirm('确定要删除吗？').then(function (result) {
                if (result) {
                    var deleteline = document.getElementsByName("CreateOrderLineListcheckedline");
                    for (i = 0; i < deleteline.length; i++) {
                        if (deleteline[i].checked == true) {
                            $scope.lineArr.splice(i, 1);
                            $scope.linecount = $scope.linecount - 1;
                        }
                    }
                }
            });
        }


        //CreateOrderLineList 按钮控制-----结束

        //殷秀利， 客户、料品
        $scope.onItemSuccess = function (data) {
            u9.hideLoading();
            $scope.queryItemData = [];
            if (data.length == 0) {

                u9.alert("没有找到符合条件的料品信息。");
            }
            for (var i = data.length - 1; i >= 0; i--) {
                var data1 = {
                    Name: data[i].Name,
                    Code: data[i].Code,
                    ID: data[i].ID,
                    UomID: data[i].Uom.ID,
                    UomCode: data[i].Uom.Code,
                    UomName: data[i].Uom.Name,
                    UomPres: data[i].Pres
                };
                $scope.queryItemData.push(data1);
            }
            ;
            $scope.$apply();
        };


        $scope.onCustomerSuccess = function (data) {
            u9.hideLoading();
            $scope.queryCustomerData = [];
            if (data.length == 0) {
                u9.alert("没有找到符合条件的客户信息。");
            }
            for (var i = data.length - 1; i >= 0; i--) {
                var data1 = {
                    Name: data[i].Name,
                    Code: data[i].Code,
                    ShortName: data[i].ShortName,
                    ID: data[i].ID,
                    CurrencyID: data[i].Currency.ID,
                    CurrencyCode: data[i].Currency.Code,
                    CurrencySymbol: data[i].Currency.Symbol,
                    CurrencyName: data[i].Currency.Name
                };
                $scope.queryCustomerData.push(data1);
            }
            ;
            $scope.$apply();
        };


        $scope.onCustomerFailure = function (data) {
            u9.alert("没有找到符合条件的客户信息。");
        };

        $scope.onItemFailure = function (data) {
            u9.hideLoading();
            u9.alert("没有找到符合条件的料品信息。");
        };

        $scope.searchCondition = function () {
            var searchCondition = $scope.data.search_Condition;
            var searchitemCondition = {
                Code: searchCondition,
                Name: searchCondition,
                OrgCode: $scope.item.code
            };
            var jsonData1 = {
                name: 'UFIDA.U9.ISV.MSV.IQueryItemService',
                params: [searchitemCondition],
                onSuccess: $scope.onItemSuccess,
                onFailure: $scope.onItemFailure
            };
            u9.showLoading();
            u9.callSV(jsonData1);
        };

        $scope.test = {
            code: ''
        };
        $scope.item = {
            code: ''
        };

        $scope.searchCustomerCondition = function () {
            //if ($scope.data.Customersearch_Condition != "") {
            //调用服务获取数据
            var searchCondition = $scope.data.Customersearch_Condition;
            var searchCustomerCondition1 = {
                Code: searchCondition,
                Name: searchCondition,
                OrgCode: $scope.test.code
            };
            var jsonData1 = {
                name: 'UFIDA.U9.ISV.MSV.IQueryCustomerService',
                params: [searchCustomerCondition1],
                onSuccess: $scope.onCustomerSuccess,
                onFailure: $scope.onCustomerFailure
            };
            u9.showLoading();
            u9.callSV(jsonData1);
        };


        $scope.Delete = function () {
            //var  Sos="";

            $scope.onDeleteSuccess = function (data) {
                u9.hideLoading();
                u9.alert("删除成功");
            };


            $scope.onDeleteFailure = function (data) {
                u9.hideLoading();
                u9.alert("删除失败，失败原因:" + data._message);
            };

            var Sos = [1001408137565337, 1001408137565371];

            var ContextDTO = "";

            var result = {
                name: 'UFIDA.U9.ISV.SM.SOShipAppSV.IDeleteSOSV',
                params: [Sos, ''],
                onSuccess: $scope.onDeleteSuccess,
                onFailure: $scope.onDeleteFailure
            };
            u9.showLoading();
            u9.callSV(result);
        };


        $scope.sendcustomerId = function (index) {
            $state.go('SoHead');
            $scope.sohead.customername = $scope.queryCustomerData[index].Name;
            $scope.sohead.customercode = $scope.queryCustomerData[index].Code;
            $scope.sohead.customerid = $scope.queryCustomerData[index].ID;
            $scope.sohead.currencyid = $scope.queryCustomerData[index].CurrencyID;
            $scope.sohead.currencycode = $scope.queryCustomerData[index].CurrencyCode;
            $scope.sohead.currencyname = $scope.queryCustomerData[index].CurrencyName;
            $scope.sohead.currencysymbol = $scope.queryCustomerData[index].CurrencySymbol;
            //清空输入框内容
            $scope.data.Customersearch_Condition = "";

            //客户改变之后头上信息需要重新收集
            $scope.headArr = []; //首先清空头内容
            $scope.headArr.push({
                docno: $scope.sohead.docno,
                customername: $scope.sohead.customername,
                customercode: $scope.sohead.customercode,
                customerid: $scope.sohead.customerid,
                currencyid: $scope.sohead.currencyid,
                currencyname: $scope.sohead.currencyname,
                currencycode: $scope.sohead.currencycode,
                //currencysymbol: $scope.sohead.currencysymbol,
                requiredate: $scope.sohead.requiredate
            });


        }

        $scope.clearItemInput = function () {
            $scope.data.search_Condition = "";
        };

        $scope.sendItemId = function (index) {
            if ($scope.modifyitemisfrom == "CreateSoLine") {
                $state.go('SoLine');
                $scope.soline.itemcode = $scope.queryItemData[index].Code;
                $scope.soline.itemname = $scope.queryItemData[index].Name;
                $scope.soline.itemid = $scope.queryItemData[index].ID;
                $scope.soline.puid = $scope.queryItemData[index].UomID;
                $scope.soline.pucode = $scope.queryItemData[index].UomCode;
                $scope.soline.puname = $scope.queryItemData[index].UomName;
                $scope.soline.presion = $scope.queryItemData[index].UomPres;
            } else {
                var solinedetailindex = $scope.slideIndex;
                $scope.myList[solinedetailindex].ItemInfo.Code = $scope.queryItemData[index].Code;
                $scope.myList[solinedetailindex].ItemInfo.Name = $scope.queryItemData[index].Name;
                $scope.myList[solinedetailindex].ItemInfo.ID = $scope.queryItemData[index].ID;
                $scope.myList[solinedetailindex].UN.Name = $scope.queryItemData[index].UomName;
                $scope.myList[solinedetailindex].UN.Code = $scope.queryItemData[index].UomCode;
                $scope.myList[solinedetailindex].UN.ID = $scope.queryItemData[index].UomID;
                $state.go('SoLineDetail');
            }

            //清空输入框内容
            $scope.data.search_Condition = "";
        }

        //方霞--结束
        //取消选中按钮
        $scope.orderlistcancelselected = function (name) {
            var ids = document.getElementsByName(name)
            for (var i = 0; i < ids.length; i++) {
                ids[i].checked = false;
            }
        }
        $scope.date = {
            selectMonth: '',
            level: ''
        };
        $scope.selectMyDate = function ($event) {
            // 创建open方法 。 下面默认行为并将opened 设为true
            var ids = event.target.id;
            var options = {
                date: $scope.date.level || new Date(),
                mode: 'date',
                doneButtonLabel: '确定',
                cancelButtonLabel: "取消"
            };

            parent.datePicker.show(options, function (date) {

                $scope.$apply(function () {
                    if (date == 'Invalid Date' || date == 'Nan-Nan') {
                        return;
                    }
                    $scope.date.level = date;
                    if (ids == 'sohead.requiredate') {
                        $scope.sohead.requiredate = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
                    }
                    if (ids == 'soline.requiredate') {
                        $scope.soline.requiredate = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
                    }
                    if (ids == 'x.RequireDate') {
                        $scope.x.RequireDate = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
                    }

                    if (ids == 'selectdate') {
                        $scope.selectdate = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
                    }

                })

            });
        }
    });

});